/*---------------------------------------------------------------*/ /* */ /* MACRO : SREGSUB */ /* FILENAME: sregsub.sas */ /* REQUIRES: Base SAS and SAS/STAT Software */ /* Release 8.0 or later */ /* */ /*---------------------------------------------------------------*/ /*--------------------------------------------------------*/ /* */ /* %global */ /* */ /*--------------------------------------------------------*/ %global nobs nonmiss miss wsum nonmisswsum misswsum subnobs subnonmiss submiss subwsum subnonmisswsum submisswsum errstr errpsu; /*--------------------------------------------------------*/ /* */ /* %scaler */ /* */ /*--------------------------------------------------------*/ %macro scaler; /*---determine n ---*/ proc means data=_d noprint; var &yvar; output out=_e(keep=n) n=n; run; data _null_; set _e; call symput('n',n); data _null_; /*---determine p for effects and parameterestimates---*/ data _null_; set _eff1; _p=numdf &plusint; if effect='Model' then call symput('p',_p); /*---determine p for contrasts and estimates---*/ data _null_; set _effects1; _p=numdf &plusint; if effect='Model' then call symput('p2',_p); /*---apply scaler correction---*/ data &effects; set _eff1; &assignsubpop; if (&applyscaler) then do; fvalue= ((&n-1)/(&n-&p)) *fvalue; probf= 1-probf(fvalue,numdf,dendf); end; data _parmest1; set _parmest1; _order=_n_; proc sort data=_parmest1; by parameter; run; proc sort data=_pe1; by parameter; run; data ¶meters(keep=parameter estimate stderr dendf tvalue probt &climits &keepsubpop _order); merge _pe1(in=ina) _parmest1(in=inb keep=parameter _order); by parameter; &assignsubpop; if (inb and not ina) then do; estimate=0; stderr=0; tvalue=.; probt=.; lowercl=.; uppercl=.; end; else if (dendf=0) then do; stderr=0; tvalue=.; probt=.; lowercl=estimate; uppercl=estimate; end; else if (stderr lt 1e-15) then do; tvalue=.; probt=.; lowercl=.; uppercl=.; end; else if (&applyscaler) then do; stderr= sqrt((&n-&p)/(&n-1))*stderr; tvalue= estimate/stderr; probt= 2*(1-probt(abs(tvalue),dendf)); lowercl=sum(estimate,-(tinv(1-&alpha/2,&df)*stderr) ); uppercl=sum(estimate, (tinv(1-&alpha/2,&df)*stderr) ); end; proc sort data=¶meters out=¶meters(drop=_order); by _order; %if (&contrastrequest) %then %do; data &contrasts; set _con1; &assignsubpop; if (&applyscaler) then do; fvalue= ((&n-1)/(&n-&p2)) *fvalue; probf= 1-probf(fvalue,numdf,dendf); end; %end; %if (&estimaterequest) %then %do; data &estimates(keep=estimatelabel estimate stderr dendf tvalue probt &climits &keepsubpop); set _est1; &assignsubpop; if (dendf=0) then do; stderr=0; tvalue=.; probt=.; lowercl=estimate; uppercl=estimate; end; else if (stderr lt 1e-15) then do; tvalue=.; probt=.; lowercl=.; uppercl=.; end; else if (&applyscaler) then do; stderr= sqrt((&n-&p2)/(&n-1))*stderr; tvalue= estimate/stderr; probt= 2*(1-probt(abs(tvalue),dendf)); lowercl=sum(estimate,-(tinv(1-&alpha/2,&df)*stderr) ); uppercl=sum(estimate, (tinv(1-&alpha/2,&df)*stderr) ); end; %end; %mend scaler; /*--------------------------------------------------------*/ /* */ /* %datasummary */ /* */ /*--------------------------------------------------------*/ %macro datasummary; /*---observations and weight sums---*/ proc means data=_d noprint; var _one; weight &weight; class _obsmiss; output out=_dsum1(keep=_obsmiss n sumwgt) n=n sumwgt=sumwgt; run; data _null_; set _dsum1; _zero=0; if _n_=1 then do; call symput('miss',_zero); call symput('misswsum',_zero); end; if _obsmiss=. then do; call symput('nobs',n); call symput('wsum',round(sumwgt)); end; else if _obsmiss=1 then do; call symput('nonmiss',n); call symput('nonmisswsum',round(sumwgt)); end; else if _obsmiss=2 then do; call symput('miss',n); call symput('misswsum',round(sumwgt)); end; /*---subpopulation observations and weight sums---*/ %if (&isubpop) %then %do; proc means data=_d noprint; var _one; weight &weight; class _obsmiss; where &rsubpop2; output out=_dsum1(keep=_obsmiss subn subsumwgt) n=subn sumwgt=subsumwgt; run; data _null_; set _dsum1; _zero=0; if _n_=1 then do; call symput('submiss',_zero); call symput('submisswsum',_zero); end; if _obsmiss=. then do; call symput('subnobs',subn); call symput('subwsum',round(subsumwgt)); end; else if _obsmiss=1 then do; call symput('subnonmiss',subn); call symput('subnonmisswsum',round(subsumwgt)); end; else if _obsmiss=2 then do; call symput('submiss',subn); call symput('submisswsum',round(subsumwgt)); end; %end; /*---weighted mean, r-square---*/ data _ds2; set _ds1; if substr(label1,1,16)='Weighted Mean of' then call symput('ymean',round(nvalue1,.00001)); data _fs2; set _fs1; if label1='R-square' then call symput('rsquare',round(nvalue1,.00001)); %mend datasummary; /*--------------------------------------------------------*/ /* */ /* %genreg */ /* */ /*--------------------------------------------------------*/ %macro genreg; /*---determine modelrequest and modeloptions---*/ %let slash=%index(&model,/); %if (&slash) %then %do; %let modelrequest=%substr(&model,1,&slash-1); %let modeloptions=%substr(&model,&slash+1); %let noint=%index(%upcase(&modeloptions),NOINT); %let clparm=%index(%upcase(&modeloptions),CLPARM); %end; %else %do; %let modelrequest=&model; %let modeloptions=; %let noint=0; %let clparm=0; %end; %if (&noint) %then %let plusint=+0; %else %let plusint=+1; %if (&clparm) %then %let climits=lowercl uppercl; %else %let climits=; /*---create modelvars---*/ %let equal=%index(&modelrequest,=); %let yvar=%substr(&modelrequest,1,&equal-1); %if %length(&modelrequest)=&equal %then %do; %let effectvars=; %let xvars=; %end; %else %do; %let effectvars=%substr(&modelrequest,&equal+1); %let xvars=%sysfunc(translate(&effectvars, ' ', '*', ' ', '|', ' ', '(', ' ', ')' )); %end; %let modelvars=&yvar &xvars; /*---check required numeric variables---*/ proc contents data=&data(keep=&modelvars &popsize &weight &subpopvar &strata) out=_vars1(keep=type) noprint; data _vars2; set _vars1; if type=2 then call symput('err101','1'); data _null_; %if (&err101) %then %goto exit; /*---process strata and get psu counts---*/ %if %length(&strata) %then %let assignstrata=_strata=&strata; %else %let assignstrata=_strata=1; %if %length(&popsize) %then %let assigntotal=_total_=&popsize; %else %let assigntotal=_total_=1e100; %let ipopsize=%length(&popsize); %if (&ipopsize) %then %do; %let totaloption1=total=_d; %let totaloption2=total=_d2; %end; %else %do; %let totaloption1=; %let totaloption2=; %end; /*---assign clustercheck---*/ %if (&sysver ge 8.1) %then %do; %if (%length(&cluster)) %then %do; %let clusters_variable=&weight._clusters; %let clustercheck=or &weight._clusters=1; %let assignnpsu=_npsu+&weight._clusters; %let errpsu=cluster (&cluster); %end; %else %do; %let clusters_variable=; %let clustercheck=; %let assignnpsu=_npsu+nobs; %let errpsu=observation; %end; %end; %else %do; %if (%length(&cluster)) %then %do; %let clusters_variable=clusters_for_&weight; %let clustercheck=or clusters_for_&weight=1; %let assignnpsu=_npsu+clusters_for_&weight; %let errpsu=cluster (&cluster); %end; %else %do; %let clusters_variable=; %let clustercheck=; %let assignnpsu=_npsu+nobs; %let errpsu=observation; %end; %end; %if (&isubpop) %then %do; %let assignsubpopvar2= _subpopvar2=&subpopvar; %let rsubpop2= %sysfunc(tranwrd(&rsubpop,&subpopvar,_subpopvar2)); %end; %else %do; %let assignsubpopvar2=; %let rsubpop2=1=1; %end; /*---process strata and clusters---*/ %let wor=0; %if %length(&strata) %then %do; proc surveymeans data=&data(keep=&strata &cluster &weight) &stacking; strata &strata /list; cluster &cluster; var &weight; ods output stratainfo=_sinfo1; run; /*---get popsize values---*/ %if %length(&popsize) %then %do; proc means data=&data(keep=&strata &popsize) max; var &popsize; class &strata; output out=_popvalues1(keep=_type_ &strata _pop) max=_pop; run; data _popvalues2; set _popvalues1 end=last; if _type_=1; if (_type_=1 and _pop gt 0) then _wor+1; if last then call symput('wor',_wor); %end; %else %do; data _popvalues2(keep=&strata _pop); set _sinfo1; _pop=-1; %end; /*--- check for one obs or one cluster ---*/ /*--- in noncertainty strata ---*/ data _sinfo2; merge _sinfo1 _popvalues2 end=last; by &strata; if (nobs=1 &clustercheck) and (_pop not in (0 1)) then do; call symput('err102','1'); call symput('errstr',trim(left(&strata))); end; _nstrata+1; &assignnpsu; if last then do; _df=_npsu-_nstrata; call symput('nstrata',trim(left(_nstrata))); call symput('nstr',_nstrata); call symput('npsu',_npsu); call symput('df',_df); end; run; data _null_; %if (&err102) %then %goto exit; /*---convert column level file to row file---*/ %if %length(&cluster) %then %let psucount=&clusters_variable; %else %let psucount=nobs; data _sinfo3(keep=_s1-_s&nstrata _count1-_count&nstrata _pop1-_pop&nstrata); merge _sinfo1 _popvalues2 end=last; by &strata; retain _s1-_s&nstrata _count1-_count&nstrata _pop1-_pop&nstrata; array _s{&nstrata} _s1-_s&nstrata; array _count{&nstrata} _count1-_count&nstrata; array _pops{&nstrata} _pop1-_pop&nstrata; _scode=&strata; _countsamp=&psucount; _popsize=_pop; _s{_n_}=_scode; _count{_n_}=_countsamp; _pops{_n_}=_popsize; if last then output; %end; %else %do; /*---get popsize value---*/ %if %length(&popsize) %then %do; proc means data=&data(keep=&popsize) max; var &popsize; output out=_popvalues2(keep=_pop1) max=_pop1; run; data _null_; set _popvalues2; if (_pop1 gt 0) then call symput('wor',_pop1); %end; %else %do; data _popvalues2; _pop1=-1; output; %end; %if (&sysver ge 8.1) %then %do; %let n_var= &weight._n; %let nclus_var= &weight._clusters; %end; %else %do; %let n_var= n_for_&weight; %let nclus_var= clusters_for_&weight; %end; %if %length(&cluster) %then %do; proc surveymeans data=&data(keep=&cluster &weight) ncluster &stacking; cluster &cluster; var &weight; ods output statistics=_sinfo1; run; data _sinfo3(keep=_s1 _count1 _pop1); merge _sinfo1 _popvalues2; _nstrata=1; _df=&nclus_var-1; if (&nclus_var=1) and (_pop1 not in (0 1)) then do; call symput('err102','1'); call symput('errstr','1'); end; call symput('nstrata',trim(left(_nstrata))); call symput('nstr',_nstrata); call symput('npsu',&nclus_var); call symput('df',_df); _s1=1; _count1=&nclus_var; %end; %else %do; proc surveymeans data=&data(keep=&weight) nobs &stacking; var &weight; ods output statistics=_sinfo1; run; data _sinfo3(keep=_s1 _count1 _pop1); merge _sinfo1 _popvalues2; _nstrata=1; _df=&n_var-1; if (&n_var=1) and (_pop1 not in (0 1)) then do; call symput('err102','1'); call symput('errstr','1'); end; call symput('nstrata',trim(left(_nstrata))); call symput('nstr',_nstrata); call symput('npsu',&n_var); call symput('df',_df); _s1=1; _count1=&n_var; %end; %if (&err102) %then %goto exit; %end; /*---put unique variable names into macro variable ---*/ proc contents data=&data(keep=&modelvars) out=_c1(keep=name varnum) noprint; run; proc means data=_c1 noprint; var varnum; output out=_c2(keep=n) n=n; run; data _null_; set _c2; call symput('numvars',n); data _null_; %let sortedvars=; %do i=1 %to &numvars; data _null_; set _c1; if _n_=&i then call symput('tempvar',name); data _null_; %let sortedvars=&sortedvars &tempvar; %end; /*---get minimums---*/ proc means data=&data noprint; var &sortedvars; output out=_b(drop=_type_ _freq_) min(&sortedvars)= / autoname; where &rsubpop; run; /*---put minimum variable names into macro variable---*/ proc contents data=_b out=_c2(keep=name) noprint; %let minvars=; %do i=1 %to &numvars; data _null_; set _c2; if _n_=&i then call symput('tempvar',name); data _null_; %let minvars=&minvars &tempvar; %end; /*---prepare input data---*/ data _d _chklev(keep=&class &modelvars &subpopvar); set &data(keep=&strata &cluster &popsize &weight &class &modelvars &subpopvar); if _n_=1 then set _b; if _n_=1 then set _sinfo3; array _s{&nstrata} _s1-_s&nstrata; array _count{&nstrata} _count1-_count&nstrata; array _pop{&nstrata} _pop1-_pop&nstrata; array _sortedvars {&numvars} &sortedvars; array _minvars {&numvars} &minvars; if (&rsubpop) then output _chklev; &assignstrata; &assigntotal; if (&ipopsize) then do; if _total_=-1 then _total_=1e100; do i=1 to &nstrata; if (_strata=_s{i} and _pop{i}=0) then _total_= _count{i}; end; end; &assignsubpopvar2; _obsmiss=1; _w=&weight; _one=1; if not (&rsubpop) then do; do i=1 to &numvars; _sortedvars{i}=.; end; _w=1e-20; end; do i=1 to &numvars; if (_sortedvars{i}=.) then do; _sortedvars{i}=_minvars{i}; _w=1e-20; _obsmiss=2; end; end; output _d; data _d2; set &data(keep=&strata &cluster &popsize &weight &class &modelvars &subpopvar); if _n_=1 then set _b; if _n_=1 then set _sinfo3; array _s{&nstrata} _s1-_s&nstrata; array _count{&nstrata} _count1-_count&nstrata; array _pop{&nstrata} _pop1-_pop&nstrata; array _sortedvars {&numvars} &sortedvars; array _minvars {&numvars} &minvars; &assignstrata; &assigntotal; if (&ipopsize) then do; if _total_=-1 then _total_=1e100; do i=1 to &nstrata; if (_strata=_s{i} and _pop{i}=0) then _total_= _count{i}; end; end; &assignsubpopvar2; _obsmiss=1; _w=&weight; _one=1; if not (&rsubpop) then _w=1e-20; do i=1 to &numvars; if (_sortedvars{i}=.) then do; _sortedvars{i}=_minvars{i}; _w=1e-20; _obsmiss=2; end; end; /*---run surveyreg for effects and parameterestimates---*/ proc surveyreg data=_d &totaloption1 alpha=α strata _strata /nocollapse; cluster &cluster; weight _w; class &class; model &modelrequest / &modeloptions solution; ods output datasummary=_ds1 fitstatistics=_fs1 parameterestimates=_pe1 effects=_eff1 ; run; /*---run surveyreg for contrasts and estimates---*/ proc surveyreg data=_d2 &totaloption2 alpha=α strata _strata /nocollapse; cluster &cluster; weight _w; class &class; model &modelrequest / &modeloptions solution; &contraststatement &contrast; &contraststatement2 &contrast2; &contraststatement3 &contrast3; &contraststatement4 &contrast4; &contraststatement5 &contrast5; &contraststatement6 &contrast6; &contraststatement7 &contrast7; &contraststatement8 &contrast8; &contraststatement9 &contrast9; &contraststatement10 &contrast10; &estimatestatement &estimate; &estimatestatement2 &estimate2; &estimatestatement3 &estimate3; &estimatestatement4 &estimate4; &estimatestatement5 &estimate5; &estimatestatement6 &estimate6; &estimatestatement7 &estimate7; &estimatestatement8 &estimate8; &estimatestatement9 &estimate9; &estimatestatement10 &estimate10; ods output parameterestimates=_parmest1 effects=_effects1 &outcontrasts &outestimates ; run; /*---check if unknown levels---*/ proc surveyreg data=_chklev; class &class; model &modelrequest /&modeloptions solution; ods output parameterestimates=_chkrows; run; proc means data=_pe1 noprint; var estimate; output out=_srsrows(keep=srsrows) n=srsrows; run; proc means data=_chkrows noprint; var estimate; output out=_svrrows(keep=svrrows) n=svrrows; run; data _null_; set _srsrows; call symput('srsrows',srsrows); data _null_; set _svrrows; call symput('svrrows',svrrows); data _null_; %if (&srsrows ne &svrrows) %then %let err103=1; %if (&err103) %then %goto exit; /*---edit intercept effect if class variables---*/ %if %length(&class) %then %do; data _eff1; set _eff1; if effect='Intercept' then do; numdf=.; fvalue=.; probf=.; end; %end; /*---run scaler correction, put subpop variable on output datasets ----*/ %scaler; /*--compute data summary---*/ %datasummary; /*---print data summary---*/ %if (%length(&cluster) and %length(&popsize) and &wor) %then %let iclupop=1; %else %let iclupop=0; ods select all; data _temp; _noteclupop=&iclupop; %if (&isubpop) %then %do; %let subtitle=Subpopulation : &subpop; %let title3=title3"Subpopulation : &subpop"; %let title4=title4"Dependent Variable: &yvar"; %end; %else %do; %let title3=title3"Dependent Variable: &yvar"; %let title4=; %end; %let usertitle=%sysfunc(compress(&title,"'")); title; %if (&isubpop=0) %then %do; data _null_; set _temp; file print; put "&usertitle"; put; put "The SURVEYREG SUBGROUP Macro"; put; put; put " Data Summary"; put; put "Dependent Variable: &yvar"; put; put "Total Observations &nobs" @52 "Weight Sum:&wsum"; put "Nonmissing Observations &nonmiss" @52 "Weight Sum:&nonmisswsum"; put "Missing Observations &miss" @52 "Weight Sum:&misswsum"; put; put "Number of Strata &nstr"; put "Number of PSUs &npsu"; put "Denominator Degrees of Freedom &df"; put; put "R-square &rsquare"; put "&yvar Mean" @35 "&ymean"; if (_noteclupop) then do; put; put"NOTE: Finite population correction to sample PSUs (&cluster)"; put"assumes inclusion of all listing units within sample PSUs."; end; run; %end; %else %do; data _null_; set _temp; file print; put "&usertitle"; put; put "The SURVEYREG SUBGROUP Macro"; put; put; put " Data Summary"; put; put "&subtitle"; put "Dependent Variable: &yvar"; put; put "Total Observations &nobs" @55 "Weight Sum:&wsum"; put "Subpopulation Observations &subnobs" @55 "Weight Sum:&subwsum"; put "Subpopulation Nonmissing Observations&subnonmiss" @55 "Weight Sum:&subnonmisswsum"; put "Subpopulation Missing Observations &submiss" @55 "Weight Sum:&submisswsum"; put; put "Number of Strata &nstr"; put "Number of PSUs &npsu"; put "Denominator Degrees of Freedom &df"; put; put "R-square &rsquare"; put "&yvar Mean" @38 "&ymean"; if (_noteclupop) then do; put; put"NOTE: Finite population correction to sample PSUs (&cluster)"; put"assumes inclusion of all listing units within sample PSUs."; end; run; %end; /*---print setup---*/ %if (%length(&fmtcell)) %then %do; %let tabformat=format=&fmtcell; %let fmt4=&fmtcell; %end; %else %do; %let tabformat=; %let fmt4=12.4; %end; %if %length(&climits) %then %let printclimits=lowercl*f=&fmt4 uppercl*f=&fmt4; %else %let printclimits=; /*---print results---*/ proc tabulate data=&effects &tabformat formchar='|----|+|---' noseps; class effect /order=data; var numdf fvalue probf; table effect, (numdf fvalue probf*f=&fmt4)*max=' ' / box="Effect" rts=&colwidth indent=1; label numdf='Num DF' fvalue='Wald F'; title' Test of Model Effects'; &title3; &title4; run; proc tabulate data=¶meters &tabformat formchar='|----|+|---' noseps; class parameter /order=data; var estimate stderr tvalue probt &climits; table parameter, (estimate*f=&fmt4 stderr*f=&fmt4 tvalue probt*f=&fmt4 &printclimits)*max=' ' / box="Parameter" rts=&colwidth indent=1; title' Estimated Regression Coefficients'; &title3; &title4; run; %if (&contrastrequest) %then %do; proc tabulate data=&contrasts &tabformat formchar='|----|+|---' noseps; class contrastlabel /order=data; var numdf fvalue probf; table contrastlabel, (numdf fvalue probf*f=&fmt4)*max=' ' / box="Contrast" rts=&colwidth indent=1; label numdf='Num DF' fvalue='Wald F'; title' Analysis of Contrasts'; &title3; &title4; run; %end; %if (&estimaterequest) %then %do; proc tabulate data=&estimates &tabformat formchar='|----|+|---' noseps; class estimatelabel /order=data; var estimate stderr tvalue probt &climits; table estimatelabel, (estimate*f=&fmt4 stderr*f=&fmt4 tvalue probt*f=&fmt4 &printclimits)*max=' ' / box="Parameter" rts=&colwidth indent=1; title' Analysis of Estimable Functions'; &title3; &title4; run; %end; %if (&eoptionrequestc or &eoptionrequeste) %then %do; proc surveyreg data=_d2; class &class; model &modelrequest; &contraststatement &contrast; &contraststatement2 &contrast2; &contraststatement3 &contrast3; &contraststatement4 &contrast4; &contraststatement5 &contrast5; &contraststatement6 &contrast6; &contraststatement7 &contrast7; &contraststatement8 &contrast8; &contraststatement9 &contrast9; &contraststatement10 &contrast10; &estimatestatement &estimate; &estimatestatement2 &estimate2; &estimatestatement3 &estimate3; &estimatestatement4 &estimate4; &estimatestatement5 &estimate5; &estimatestatement6 &estimate6; &estimatestatement7 &estimate7; &estimatestatement8 &estimate8; &estimatestatement9 &estimate9; &estimatestatement10 &estimate10; ods select &concoef &estcoef; title; title3; title4; run; %end; %exit: %mend genreg; /*--------------------------------------------------------*/ /* */ /* %sregsub */ /* */ /*--------------------------------------------------------*/ %macro sregsub( data=, weight=, class=, model=, popsize=, alpha=.05, strata=, cluster=, contrast=, estimate=, subpop=, fmtcell=, colwidth=26, output=, title=The SAS System, contrast2=, contrast3=, contrast4=, contrast5=, contrast6=, contrast7=, contrast8=, contrast9=, contrast10=, estimate2=, estimate3=, estimate4=, estimate5=, estimate6=, estimate7=, estimate8=, estimate9=, estimate10=, varmult= ) ; ods exclude all; options nocenter nonumber nodate nostimer formdlim=' ' formchar="|----|+|---+=|-/\<>*"; %if (&sysver ge 8.1) %then %do; ods noproctitle; %end; /*---for v9 or higher, use stacking option---*/ %if (&sysver ge 9.0) %then %let stacking=stacking; %else %let stacking=; /*---initialize error indicators---*/ %let err1=0; %let err2=0; %let err3=0; %let err4=0; %let err5=0; %let err101=0; %let err102=0; %let err103=0; /*---check required parameters---*/ %if (%length(&data)=0) or (%length(&model)=0) or (%length(&weight)=0) %then %let err1=1; /*---check strata and cluster parameters---*/ %let err2=%length(%scan(&strata,2)); %let err3=%length(%scan(&cluster,2)); /*---intialize contrast and estimate stuff---*/ %let contraststatement=; %let estimatestatement=; %let eoptioncon=0; %let eoptionest=0; %let conoptions=0; %let estoptions=0; %do i=2 %to 10; %let contraststatement&i=; %let estimatestatement&i=; %let eoptioncon&i=0; %let eoptionest&i=0; %let conoptions&i=0; %let estoptions&i=0; %end; /*---contrast requests---*/ %if (%length(&contrast) or %length(&contrast2) or %length(&contrast3) or %length(&contrast4) or %length(&contrast5) or %length(&contrast6) or %length(&contrast7) or %length(&contrast8) or %length(&contrast9) or %length(&contrast10) ) %then %do; %let contrastrequest=1; %let outcontrasts=contrasts=_con1; %if %length(&contrast) %then %do; %let slashcon=%index(&contrast,/); %if (&slashcon) %then %do; %let conoptions=%upcase(%substr(&contrast,&slashcon+1)); %let eoptioncon=%index(&conoptions,E); %end; %let contraststatement=contrast; %let contrast=%sysfunc(translate(&contrast,',','&')); %end; %if %length(&contrast2) %then %do; %let slashcon2=%index(&contrast2,/); %if (&slashcon2) %then %do; %let conoptions2=%upcase(%substr(&contrast2,&slashcon2+1)); %let eoptioncon2=%index(&conoptions2,E); %end; %let contraststatement2=contrast; %let contrast2=%sysfunc(translate(&contrast2,',','&')); %end; %if %length(&contrast3) %then %do; %let slashcon3=%index(&contrast3,/); %if (&slashcon3) %then %do; %let conoptions3=%upcase(%substr(&contrast3,&slashcon3+1)); %let eoptioncon3=%index(&conoptions3,E); %end; %let contraststatement3=contrast; %let contrast3=%sysfunc(translate(&contrast3,',','&')); %end; %if %length(&contrast4) %then %do; %let slashcon4=%index(&contrast4,/); %if (&slashcon4) %then %do; %let conoptions4=%upcase(%substr(&contrast4,&slashcon4+1)); %let eoptioncon4=%index(&conoptions4,E); %end; %let contraststatement4=contrast; %let contrast4=%sysfunc(translate(&contrast4,',','&')); %end; %if %length(&contrast5) %then %do; %let slashcon5=%index(&contrast5,/); %if (&slashcon5) %then %do; %let conoptions5=%upcase(%substr(&contrast5,&slashcon5+1)); %let eoptioncon5=%index(&conoptions5,E); %end; %let contraststatement5=contrast; %let contrast5=%sysfunc(translate(&contrast5,',','&')); %end; %if %length(&contrast6) %then %do; %let slashcon6=%index(&contrast6,/); %if (&slashcon6) %then %do; %let conoptions6=%upcase(%substr(&contrast6,&slashcon6+1)); %let eoptioncon6=%index(&conoptions6,E); %end; %let contraststatement6=contrast; %let contrast6=%sysfunc(translate(&contrast6,',','&')); %end; %if %length(&contrast7) %then %do; %let slashcon7=%index(&contrast7,/); %if (&slashcon7) %then %do; %let conoptions7=%upcase(%substr(&contrast7,&slashcon7+1)); %let eoptioncon7=%index(&conoptions7,E); %end; %let contraststatement7=contrast; %let contrast7=%sysfunc(translate(&contrast7,',','&')); %end; %if %length(&contrast8) %then %do; %let slashcon8=%index(&contrast8,/); %if (&slashcon8) %then %do; %let conoptions8=%upcase(%substr(&contrast8,&slashcon8+1)); %let eoptioncon8=%index(&conoptions8,E); %end; %let contraststatement8=contrast; %let contrast8=%sysfunc(translate(&contrast8,',','&')); %end; %if %length(&contrast9) %then %do; %let slashcon9=%index(&contrast9,/); %if (&slashcon9) %then %do; %let conoptions9=%upcase(%substr(&contrast9,&slashcon9+1)); %let eoptioncon9=%index(&conoptions9,E); %end; %let contraststatement9=contrast; %let contrast9=%sysfunc(translate(&contrast9,',','&')); %end; %if %length(&contrast10) %then %do; %let slashcon10=%index(&contrast10,/); %if (&slashcon10) %then %do; %let conoptions10=%upcase(%substr(&contrast10,&slashcon10+1)); %let eoptioncon10=%index(&conoptions10,E); %end; %let contraststatement10=contrast; %let contrast10=%sysfunc(translate(&contrast10,',','&')); %end; %end; %else %do; %let contrastrequest=0; %let outcontrasts=; %end; %if (&eoptioncon or &eoptioncon2 or &eoptioncon3 or &eoptioncon4 or &eoptioncon5 or &eoptioncon6 or &eoptioncon7 or &eoptioncon8 or &eoptioncon9 or &eoptioncon10) %then %do; %let eoptionrequestc=1; %let concoef=contrastcoef; %end; %else %do; %let eoptionrequestc=0; %let concoef=; %end; /*---estimate requests---*/ %if (%length(&estimate) or %length(&estimate2) or %length(&estimate3) or %length(&estimate4) or %length(&estimate5) or %length(&estimate6) or %length(&estimate7) or %length(&estimate8) or %length(&estimate9) or %length(&estimate10) ) %then %do; %let estimaterequest=1; %let outestimates=estimates=_est1; %if %length(&estimate) %then %do; %let slashest=%index(&estimate,/); %if (&slashest) %then %do; %let estoptions=%upcase(%substr(&estimate,&slashest+1)); %let eoptionest=%index(&estoptions,E); %end; %let estimatestatement=estimate; %end; %if %length(&estimate2) %then %do; %let slashest2=%index(&estimate2,/); %if (&slashest2) %then %do; %let estoptions2=%upcase(%substr(&estimate2,&slashest2+1)); %let eoptionest2=%index(&estoptions2,E); %end; %let estimatestatement2=estimate; %end; %if %length(&estimate3) %then %do; %let slashest3=%index(&estimate3,/); %if (&slashest3) %then %do; %let estoptions3=%upcase(%substr(&estimate3,&slashest3+1)); %let eoptionest3=%index(&estoptions3,E); %end; %let estimatestatement3=estimate; %end; %if %length(&estimate4) %then %do; %let slashest4=%index(&estimate4,/); %if (&slashest4) %then %do; %let estoptions4=%upcase(%substr(&estimate4,&slashest4+1)); %let eoptionest4=%index(&estoptions4,E); %end; %let estimatestatement4=estimate; %end; %if %length(&estimate5) %then %do; %let slashest5=%index(&estimate5,/); %if (&slashest5) %then %do; %let estoptions5=%upcase(%substr(&estimate5,&slashest5+1)); %let eoptionest5=%index(&estoptions5,E); %end; %let estimatestatement5=estimate; %end; %if %length(&estimate6) %then %do; %let slashest6=%index(&estimate6,/); %if (&slashest6) %then %do; %let estoptions6=%upcase(%substr(&estimate6,&slashest6+1)); %let eoptionest6=%index(&estoptions6,E); %end; %let estimatestatement6=estimate; %end; %if %length(&estimate7) %then %do; %let slashest7=%index(&estimate7,/); %if (&slashest7) %then %do; %let estoptions7=%upcase(%substr(&estimate7,&slashest7+1)); %let eoptionest7=%index(&estoptions7,E); %end; %let estimatestatement7=estimate; %end; %if %length(&estimate8) %then %do; %let slashest8=%index(&estimate8,/); %if (&slashest8) %then %do; %let estoptions8=%upcase(%substr(&estimate8,&slashest8+1)); %let eoptionest8=%index(&estoptions8,E); %end; %let estimatestatement8=estimate; %end; %if %length(&estimate9) %then %do; %let slashest9=%index(&estimate9,/); %if (&slashest9) %then %do; %let estoptions9=%upcase(%substr(&estimate9,&slashest9+1)); %let eoptionest9=%index(&estoptions9,E); %end; %let estimatestatement9=estimate; %end; %if %length(&estimate10) %then %do; %let slashest10=%index(&estimate10,/); %if (&slashest10) %then %do; %let estoptions10=%upcase(%substr(&estimate10,&slashest10+1)); %let eoptionest10=%index(&estoptions10,E); %end; %let estimatestatement10=estimate; %end; %end; %else %do; %let estimaterequest=0; %let outestimates=; %end; %if (&eoptionest or &eoptionest2 or &eoptionest3 or &eoptionest4 or &eoptionest5 or &eoptionest6 or &eoptionest7 or &eoptionest8 or &eoptionest9 or &eoptionest10) %then %do; %let eoptionrequeste=1; %let estcoef=estimatecoef; %end; %else %do; %let eoptionrequeste=0; %let estcoef=; %end; /*---check for nofill error---*/ %if (&contrastrequest or &estimaterequest) %then %do; %if (%index(&conoptions,NOFILL) or %index(&conoptions2,NOFILL)) or (%index(&conoptions3,NOFILL) or %index(&conoptions4,NOFILL)) or (%index(&conoptions5,NOFILL) or %index(&conoptions6,NOFILL)) or (%index(&conoptions7,NOFILL) or %index(&conoptions8,NOFILL)) or (%index(&conoptions8,NOFILL) or %index(&conoptions10,NOFILL)) or (%index(&estoptions,NOFILL) or %index(&estoptions2,NOFILL)) or (%index(&estoptions3,NOFILL) or %index(&estoptions4,NOFILL)) or (%index(&estoptions5,NOFILL) or %index(&estoptions6,NOFILL)) or (%index(&estoptions7,NOFILL) or %index(&estoptions8,NOFILL)) or (%index(&estoptions8,NOFILL) or %index(&estoptions10,NOFILL)) %then %let err5=1; %end; /*---subpop request---*/ %let isubpop=%length(&subpop); %if (&isubpop=0) %then %do; %let rsubpop=1=1; %let assignsubpop=; %let subpopvar=; %let keepsubpop=; %end; %else %do; %let rsubpop=&subpop; %let assignsubpop=Subpop="&subpop"; %let word2=%upcase(%scan(&rsubpop,2)); %let poperator=%sysfunc( indexc(&rsubpop,'~=^><') ); %if (&poperator) %then %let subpopvar=%substr(&rsubpop,1,&poperator-1); %else %if ( %index(&word2,EQ) or %index(&word2,NE) or %index(&word2,GT) or %index(&word2,LT) or %index(&word2,GE) or %index(&word2,LE) or %index(&word2,IN) ) %then %let subpopvar=%scan(&rsubpop,1); %else %let err4=1; %let keepsubpop=subpop; %end; /*---first set of error checks---*/ %if (&err1 or &err2 or &err3 or &err4 or &err5) %then %do; %put; %put; %put; %if (&err1) %then %put ERROR: Missing one or more required parameters (DATA=, MODEL=, or WEIGHT= ) .; %if (&err2) %then %put ERROR: You may only specify one variable in STRATA= .; %if (&err3) %then %put ERROR: You may only specify one variable in CLUSTER= .; %if (&err4) %then %put ERROR: Please check syntax for SUBPOP= .; %if (&err5) %then %put ERROR: The NOFILL option is not allowed in the SREGSUB macro.; %put; %put; %put; %goto exit; %end; /*---output request---*/ %let effects=_eff2; %let parameters=_pe2; %let contrasts=_con2; %let estimates=_est2; %if %length(&output) %then %do; %let i=1; %let tempvar=%scan(&output,&i,%str( )); %do %until (%length(&tempvar)=0); %let equal=%index(&tempvar,=); %let leftside=%substr(&tempvar,1,&equal-1); %let rightside=%substr(&tempvar,&equal+1); %if %upcase(&leftside)=EFFECTS %then %let effects=&rightside; %else %if %upcase(&leftside)=PARAMETERESTIMATES %then %let parameters=&rightside; %else %if %upcase(&leftside)=CONTRASTS %then %let contrasts=&rightside; %else %if %upcase(&leftside)=ESTIMATES %then %let estimates=&rightside; %let i=%eval(&i+1); %let tempvar=%scan(&output,&i, %str( )); %end; %end; /*---varmult request---*/ %let ifuller=%index(%upcase(&varmult),FULLER); %if (&ifuller) %then %let applyscaler=1=2; %else %let applyscaler=1=1; %genreg; /*---second set of error checks---*/ %if (&err101 or &err102 or &err103) %then %do; %put; %put; %put; %if (&err101) %then %do; %put ERROR: Only numeric variables allowed for parameters MODEL=, CLASS=,; %put %str( )WEIGHT=, POPSIZE=, and SUBPOP=, and STRATA= .; %end; %if (&err102) %then %do; %put ERROR: Cannot compute variance. Stratum &errstr has only one noncertainty; %put %str( )&errpsu..; %end; %if (&err103) %then %do; %put ERROR: At least one cell has zero observations. The SREGSUB macro; %put %str( )is not able to fit model. You should reduce the number; %put %str( )of classification effects in your model.; %end; %put; %put; %put; %goto exit; %end; %exit: %if (&sysver ge 8.1) %then %do; ods proctitle; %end; title'The SAS System'; title2; title3; title4; ods select all; run; %mend sregsub;