/******************************************************************************* Program name: MI_SREG Programmer: Qixuan Chen, Ph.D (qc2138@columbia.edu) Department of Biostatistics Mailman School of Public Health Columbia University Date: June 2nd, 2008 Purpose: (1) Use MIANALYZE to combine the multiple regression coefficients estimates obtained using PROC SURVEYREG.In the data set "&dset", there should be one variable called "_imputation_". (2) The user need to specify the following macro variables: "dset" -- source data "outcome" -- outcome of the model "var" -- the list of covariates "catVar"-- the string of categorical variables in "varlist" "strata" -- strata in a survey sample "cluster" -- cluster in a survey sample "weight" -- sample weight "output1" -- the output of the combined beta coefficient estimates "output2" -- the output of the combined p-values (useful when there are categorical variables) ********************************************************************************/ %macro MI_SREG(dset=, outcome=, var=, catVar=, strata=, cluster=, weight=, output1=, output2=); proc surveyreg data=&dset; weight &weight; strata &strata; cluster &cluster; class &catVar; model &outcome = &var/solution adjrsq covb; by _imputation_; ods output ParameterEstimates=out; ods output DesignSummary=design; ods output covb=covariance; run; data _null_; set design; if _N_=1 then call symput('nstrata',cValue1); if _N_=2 then call symput('ncluster',cValue1); run; %let df=%eval(&ncluster-&nstrata); data out; set out; if tValue=. then delete; keep _imputation_ Parameter Estimate; run; data testvar; set out; if (_imputation_=1) and (Parameter ne 'Intercept'); space=anyspace(Parameter); if space > 1 then var=substr(Parameter, 1, space-1); else var=Parameter; run; proc freq data=testvar; tables var; ods output OneWayFreqs =freq; run; data freq; set freq; keep var frequency; run; proc sort data=freq; by frequency; run; data _null_; set freq; if _N_=1 then call symput('min',frequency); run; proc sort data=freq; by descending frequency; run; data _null_; set freq; if _N_=1 then call symput('max',frequency); run; %if &max=1 %then %do; proc mianalyze parms=out covb(effectvar=stacking)=covariance edf=&df; modeleffects Intercept &var; ods output ParameterEstimates=result; run; data result; set result; if Probt=. then Probt=(1-probt(abs(Estimate/sqrt(StdErr)),&df))*2; run; data result; set result; if Probt=<0.0001 then Probt=0; run; data test; set result; format var $40.; if Parm="Intercept" then delete; var=Parm; Prob=round(Probt,0.001); keep var Prob; run; proc datasets library=work; delete out testvar freq covariance; run; quit; %end; %else %do; %if &min=1 %then %do; data continuous; set freq; if frequency=1; drop frequency; run; proc sql noprint; select var into :continuous separated by ' ' from continuous; quit; %let nCont=0; %do %while(%scan(&continuous, %eval(&nCont+1), %str( )) NE); %let nCont=%eval(&nCont+1); %let cont&nCont=%scan(&continuous, &nCont); %end; %end; data categorical; set freq; if frequency>1; run; proc sql noprint; select var into :categorical separated by ' ' from categorical; select frequency into :catFreq separated by ' ' from categorical; quit; %let nCate=0; %do %while(%scan(&categorical, %eval(&nCate+1), %str( )) NE); %let nCate=%eval(&nCate+1); %let cate&nCate=%scan(&categorical, &nCate); %let catFreq&nCate=%scan(&catFreq, &nCate); %put &&catFreq&nCate; %end; %macro workdata(outdata, indata); data &outdata; set &indata; Parameter = trim(Parameter); length=length(Parameter); space = anyspace(Parameter); if (space > 1) and (length > space) then Variable=TRANSLATE(Parameter,'_', ' '); else Variable = Parameter; Variable = substr(Variable, 1, length); drop Parameter length space; run; %mend workdata; %workdata(out2, out); %workdata(covariance2, covariance); data MIvar; set out2; where _imputation_=1; run; proc sql noprint; select Variable into :MIvarlist separated by ' ' from MIvar; quit; %put MIVarlist=&MIvarlist; %macro imp(imp); data temp&imp; set covariance2; where _imputation_=&imp; run; data temp&imp; set temp&imp; if Intercept=0 then delete; run; proc transpose data=temp&imp out=temp&imp; ID Variable; run; data temp&imp; set temp&imp; if Intercept=0 then delete; run; proc transpose data=temp&imp out=temp&imp; run; %mend imp; %imp(1); %imp(2); %imp(3); %imp(4); %imp(5); data covariance3; set temp1 temp2 temp3 temp4 temp5; run; data covariance3; set covariance3; rename _NAME_=Variable; run; proc mianalyze parms=out2 covb(effectvar=stacking)=covariance3 edf=&df; modeleffects &MIvarlist; %if &min=1 %then %do; %do i=1 %to &nCont; &&cont&i : test &&cont&i; %end; %end; %do k=1 %to &nCate; &&cate&k : test %do j=1 %to %eval(&&catFreq&k-1); %str(&&cate&k)_&j.= %end; %str(&&cate&k)_%eval(&&catFreq&k)=0 /mult; %end; ods output TestMultStat=test ParameterEstimates=result; run; data test; set test; rename Test=Parm; if ProbF=. then ProbF=1-probf(FValue,NumDF,&df); run; data test(keep=Parm Prob); set test; rename ProbF=Prob; run; %if &min=1 %then %do; data continuous; set continuous; index=1; rename var=Parm; run; data result2(keep=Parm Prob); set result; if tValue=. then Probt=(1-Probt(abs(Estimate/sqrt(StdErr)),&df))*2; rename Probt=Prob; run; proc sort data=continuous; by Parm; run; proc sort data=result2; by Parm; run; data result2; merge continuous result2; by Parm; run; data result2; set result2; if index=1; run; data test; set test result2;run; %end; data test; set test; format var $40.; if Prob=<.0001 then Prob=0; var=Parm; keep var Prob; run; proc datasets library=work; delete CATEGORICAL CONTINUOUS COVARIANCE COVARIANCE2 COVARIANCE3 DESIGN FREQ MIVAR OUT OUT2 TEMP1 TEMP2 TEMP3 TEMP4 TEMP5 TESTVAR; run; quit; %end; data &output1; set result; run; data &output2; set test; run; %mend MI_SREG;