📄 setmod.sas
字号:
%let ods = ods output LSMeans = lsmeans%str(;);
%let rc = %sysfunc(fput(&modfile, %bquote(&ods)));
%let rc = %sysfunc(fwrite(&modfile));
%end;
%if (&cluster eq and &stratum eq and &weight eq ) %then %do;
%if (&repeated) %then %let ods = ods output GEERCov = covb1%str(;);
%else %let ods = ods output CovB = covb1%str(;);
%let rc = %sysfunc(fput(&modfile, %bquote(&ods)));
%let rc = %sysfunc(fwrite(&modfile));
%end;
%let ods = ods output ModelFit = like1%str(;);
%let rc = %sysfunc(fput(&modfile, %bquote(&ods)));
%let rc = %sysfunc(fwrite(&modfile));
%end;
%end;
%else %if (%bquote(%upcase(&procid)) eq LIFEREG) %then %do; /* proc lifereg */
%let line = %qsubstr(&line, 1, %length(%bquote(&line)) - 1);
%let line = %qtrim(&line);
%let line = %bquote(&line) covout outest=est1 noprint%str(;);
%end;
%else %if (%bquote(%upcase(&procid)) eq MIXED) %then %do; /* proc mixed */
%if (&sysver eq 6.12) %then
%let msg = Sasmod %str(doesn%'t) support proc mixed in SAS V6.12;
%else %do;
%let ods = ods select none%str(;);
%let rc = %sysfunc(fput(&modfile, %bquote(&ods)));
%let rc = %sysfunc(fwrite(&modfile));
%let ods = ods output SolutionF = est1%str(;);
%let rc = %sysfunc(fput(&modfile, %bquote(&ods)));
%let rc = %sysfunc(fwrite(&modfile));
%let ods = ods output CovParms = covparms%str(;);
%let rc = %sysfunc(fput(&modfile, %bquote(&ods)));
%let rc = %sysfunc(fwrite(&modfile));
%if (&cluster eq and &stratum eq and &weight eq ) %then %do;
%let ods = ods output CovB = covb1%str(;);
%let rc = %sysfunc(fput(&modfile, %bquote(&ods)));
%let rc = %sysfunc(fwrite(&modfile));
%end;
%let ods = ods output FitStatistics = like1%str(;);
%let rc = %sysfunc(fput(&modfile, %bquote(&ods)));
%let rc = %sysfunc(fwrite(&modfile));
%end;
%end;
%else %if (%bquote(%upcase(&procid)) eq NLIN) %then %do; /* proc nlin */
%let line = %qsubstr(&line, 1, %length(%bquote(&line)) - 1);
%let line = %qtrim(&line);
%let line = %bquote(&line) outest=est1 noprint%str(;);
%end;
%else %if (%bquote(%upcase(&procid)) eq PHREG) %then %do; /* proc phreg */
%if (&sysver eq 6.12) %then
%let msg = Sasmod %str(doesn%'t) support proc phreg in SAS V6.12;
%else %do;
%let ods = ods select none%str(;);
%let rc = %sysfunc(fput(&modfile, %bquote(&ods)));
%let rc = %sysfunc(fwrite(&modfile));
%let ods = ods output ParameterEstimates = est1%str(;);
%let rc = %sysfunc(fput(&modfile, %bquote(&ods)));
%let rc = %sysfunc(fwrite(&modfile));
%if (&cluster eq and &stratum eq and &weight eq ) %then %do;
%let ods = ods output CovB = covb1%str(;);
%let rc = %sysfunc(fput(&modfile, %bquote(&ods)));
%let rc = %sysfunc(fwrite(&modfile));
%end;
%let ods = ods output FitStatistics = like1%str(;);
%let rc = %sysfunc(fput(&modfile, %bquote(&ods)));
%let rc = %sysfunc(fwrite(&modfile));
%end;
%end;
%else %if (%bquote(%upcase(&procid)) eq PROBIT) %then %do; /* proc probit */
%let line = %qsubstr(&line, 1, %length(%bquote(&line)) - 1);
%let line = %qtrim(&line);
%let line = %bquote(&line) covout outest=est1 noprint%str(;);
%end;
%else %let msg = Sasmod %str(doesn%'t) support procedure %bquote(&procid); /* unsupported proc */
%end;
%if (%bquote(&msg) eq ) %then %do;
%let procid = %upcase(&procid); /* procedure name upper case for recognition */
%let rc = %sysfunc(fput(&modfile, %bquote(&line))); /* write proc statement */
%let rc = %sysfunc(fwrite(&modfile));
%if (&cluster ne or &stratum ne or &weight ne ) %then %do; /* write freq/weight statement */
%if (&procid ne PHREG) %then %do;
%if (&procid eq GENMOD) %then %let line = freq _WEIGHT_%str(;);
%else %let line = weight _WEIGHT_%str(;);
%let rc = %sysfunc(fput(&modfile, %bquote(&line)));
%let rc = %sysfunc(fwrite(&modfile));
%end;
%end;
%end;
%end;
%else %if (&procid eq ) %then %let msg = Sasmod %str(doesn%'t) recognize &key statement;
%else %if (%bquote(%upcase(&key)) eq CLASS) %then %do; /* class statement */
%if (&procid eq LIFEREG and &sysver eq 6.12) %then
%let msg = Sasmod %str(doesn%'t) support class statements with proc lifereg in SAS V6.12;
%else %if (&procid eq PROBIT and &sysver eq 6.12) %then
%let msg = Sasmod %str(doesn%'t) support class statements with proc probit in SAS V6.12;
%else %do;
%let rc = %sysfunc(fput(&modfile, %bquote(&line)));
%let rc = %sysfunc(fwrite(&modfile));
%end;
%end;
%else %if (%bquote(%upcase(&key)) eq FREQ) %then %do;
%let msg = Sasmod %str(doesn%'t) support freq statements%str(;) use weight instead;
%end;
%else %if (%bquote(%upcase(&key)) eq MODEL) %then %do; /* model statement */
%if (&procid eq ) %then
%let msg = Model statement must follow procedure;
%else %if (&model ne ) %then
%let msg = Repeated model statement;
%else %do; /* identify model */
%let model = %scan(%bquote(&line), 1, %str(=));
%let model = %qsubstr(&model, 6);
%let model = %qleft(%bquote(&model));
%let model = %qtrim(&model);
%if (&procid eq CATMOD) %then %do; /* proc catmod, request covariances */
%let line = %qsubstr(&line, 1, %length(%bquote(&line)) - 1);
%let line = %qtrim(&line);
%if (%index(%bquote(&line), %str(/)) eq 0) %then
%let line = %bquote(&line) /;
%if (%sysevalf(&sysver ge 9)) %then
%let line = %bquote(&line) covb itprint%str(;);
%else
%let line = %bquote(&line) covb%str(;);
%end;
%else %if (&procid eq GENMOD) %then %do; /* proc genmod, request covariances */
%let line = %qsubstr(&line, 1, %length(%bquote(&line)) - 1);
%let line = %qtrim(&line);
%if (%index(%bquote(&line), %str(/)) eq 0) %then
%let line = %bquote(&line) / covb%str(;);
%else
%let line = %bquote(&line) covb%str(;);
%end;
%else %if (&procid eq MIXED) %then %do; /* proc mixed, request solution and covariances */
%let line = %qsubstr(&line, 1, %length(%bquote(&line)) - 1);
%let line = %qtrim(&line);
%if (%index(%bquote(&line), %str(/)) eq 0) %then
%let line = %bquote(&line) / s covb%str(;);
%else
%let line = %bquote(&line) s covb%str(;);
%end;
%else %if (&procid eq PHREG) %then %do; /* proc phreg, request covariances and possibly offset */
%let line = %qsubstr(&line, 1, %length(%bquote(&line)) - 1);
%let line = %qtrim(&line);
%if (%index(%bquote(&line), %str(/)) eq 0) %then
%let line = %bquote(&line) / covb;
%else
%let line = %bquote(&line) covb;
%if (&cluster ne or &stratum ne or &weight ne ) %then
%let line = %bquote(&line) offset=_OFFSET_%str(;);
%else
%let line = %bquote(&line)%str(;);
%end;
%let rc = %sysfunc(fput(&modfile, %bquote(&line))); /* write model statement */
%let rc = %sysfunc(fwrite(&modfile));
%end;
%end;
%else %if (%bquote(%upcase(&key)) eq REPEATED) %then %do; /* repeated statement */
%if (&procid eq ) %then
%let msg = Repeated statement must follow procedure;
%else %do;
%if (&procid eq GENMOD) %then %do; /* proc genmod, request gee covariances */
%let line = %qsubstr(&line, 1, %length(%bquote(&line)) - 1);
%let line = %qtrim(&line);
%if (%index(%bquote(&line), %str(/)) eq 0) %then
%let line = %bquote(&line) / ecovb%str(;);
%else
%let line = %bquote(&line) ecovb%str(;);
%end;
%let rc = %sysfunc(fput(&modfile, %bquote(&line))); /* write model statement */
%let rc = %sysfunc(fwrite(&modfile));
%end;
%end;
%else %if (%bquote(%upcase(&key)) eq RUN) %then %do; /* run statement */
%let rc = %sysfunc(fput(&modfile, %bquote(&line)));
%let rc = %sysfunc(fwrite(&modfile));
%if (&procid eq CATMOD or &procid eq GENMOD or &procid eq MIXED or &procid eq PHREG) %then %do;
%let ods = ods select all%str(;); /* end ods output */
%let rc = %sysfunc(fput(&modfile, %bquote(&ods)));
%let rc = %sysfunc(fwrite(&modfile));
%end;
%end;
%else %do; /* other statements */
%let rc = %sysfunc(fput(&modfile, %bquote(&line)));
%let rc = %sysfunc(fwrite(&modfile));
%end;
%let line = ; /* line processed, blank it out */
%end; /* end no error message if */
%end; /* end setup line loop */
%end; /* end no error message if */
%if (%bquote(&msg) eq ) %then %do; /* check for valid proc statement */
%if (&procid eq ) %then %let msg = No proc statement;
%else %if (&procid ne CALIS and &model eq ) %then %let msg = No model statement;
%end;
%if (&setfile ne ) %then %do; /* close setup file */
%let rc = %sysfunc(fclose(&setfile));
%let rc = %sysfunc(filename(setref));
%let setfile = ;
%end;
%if (&modfile ne ) %then %do; /* close module file */
%let rc = %sysfunc(fclose(&modfile));
%let rc = %sysfunc(filename(modref));
%let modfile = ;
%end;
%if (&logfile ne ) %then %do; /* close log file */
%let rc = %sysfunc(fclose(&logfile));
%let rc = %sysfunc(filename(logref));
%let logfile = ;
%end;
%mend setmod;
%macro params; /* get parameters */
%let posn = 0;
%let result = ;
%do %until(&posn eq &count);
%let key = %scan(%bquote(&line), &posn + 2, %str( =;)); /* get next paramter */
%if (&key ne ) %then %do;
%if (&result eq ) %then %let result = &key; /* if parameter exists, concatenate it */
%else %let result = &result &key;
%let posn = %eval(&posn + 1);
%end;
%else %let count = &posn;
%end; /* if parameter doesn't exist or no more parameters desired, quit */
%mend params;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -