/**************************************************************************************************************************************** Imputation SAS code for Exemplar 6 tHIS ONE IMPUTES FROM THE big DATA FILE NOTE that you need to run the program ex6formats.sas before you can open the data files here ALSO to run the IVEWARE software you need to close all advanced editor windows and use only the old program editor CHANGE the libname to shere your data sets are stored proc contents data=ex6.ex6DETAIL short position;run; ****************************************************************************************************************************************/ libname ex6 'C:\Documents and Settings\gillian raab\My Documents\aprojects\peaslaptop\ex6datafiles\data' ; /*------------------------------------------------------------------ Now the analysis of detailed questions using the IVEWARE macros details of what the commands mean are in the user guide on the IVE site. Here all variables are treated as categorical and each has 8 categories. --------------------------------------------------------------------*/ title 'Imputation of detailed questions (subsets) with IVEWARE'; /*------------------------------------------------------------------- This took almost a day. And it only worked afer various preliminary investigations that set the stepwise procedures to have a max of 10 variables and to stop the iterations at 10 Otherwise it would have taken months -----------------------------------------------------------------------*/ data temp; set ex6.ex6det; keep caseid yayars02 ybyars02 ycyars02 ydyars02 yeyars02 yfyars02 gender ; run; %impute(name=ivesetup3, dir=C:\Documents and Settings\gillian raab\My Documents\aprojects\peaslaptop\ex6datafiles\program_code ,setup=new); title Multiple imputation detailed questions (subsets) categorical; datain temp; dataout impout all ; default categorical; maxlogi 50; iterations 5; multiples 1; transfer caseid ; print coef; run ; %include "C:\Documents and Settings\gillian raab\My Documents\aprojects\peaslaptop\ex6datafiles\program_code\checkimp_macro.sas"; %checkimp(impout,ex6.ex6det) /*---------------------------- next group--------------------*/ data temp; set ex6.ex6detail; keep caseid yayshp02 ybyshp02 ycyshp02 ydyshp02 yeyshp02 yfyshp02 yayscl02 ybyscl02 ycyscl02 ydyscl02 yayhom02 ybyhom02 ycyhom02 ydyhom02 gender ; run; %impute(name=ivesetup3, dir=C:\Documents and Settings\gillian raab\My Documents\aprojects\peaslaptop\ex6datafiles\program_code ,setup=new); title Multiple imputation prevalence only; datain temp; dataout imp2 all ; default categorical; iterations 5; multiples 2; maxlogi 50; print coef; transfer caseid ; seed 1769; run ; /*---------------------------- next group--------------------*/ data temp; set ex6.ex6detail; keep caseid yaycbk02 ybycbk02 ycycbk02 ydycbk02 yeycbk02 yfycbk02 yayjrd02 ybyjrd02 ycyjrd02 ydyjrd02 yeyjrd02 yfyjrd02 yayrob02 ybyrob02 gender ; run; %impute(name=ivesetup3, dir=C:\Documents and Settings\gillian raab\My Documents\aprojects\peaslaptop\ex6datafiles\program_code ,setup=new); title Multiple imputation prevalence only; datain temp; dataout imp3 all ; default categorical; multiples 10; print coef; transfer caseid ; seed 170; run ; /*---------------------------- next group--------------------*/ data temp; set ex6.ex6detail; keep caseid yaywep02 ybywep02 ycywep02 ydywep02 yeywep02 yfywep02 ycydrg02 ydydrg02 yeydrg02 yfydrg02 yayhit02 ybyhit02 ycyhit02 ydyhit02 yeyhit02 yfyhit02 gender ; run; %impute(name=ivesetup3, dir=C:\Documents and Settings\gillian raab\My Documents\aprojects\peaslaptop\ex6datafiles\program_code ,setup=new); title Multiple imputation prevalence only; datain temp; dataout imp4 all ; default categorical; multiples 10; print coef; transfer caseid ; seed 171; run ; /*---------------------------- next group--------------------*/ data temp; set ex6.ex6detail; keep caseid yayvnd02 ybyvnd02 ycyvnd02 ydyvnd02 yeyvnd02 yfyvnd02 yaygrf02 ybygrf02 ycygrf02 ydygrf02 yeygrf02 yayars02 ybyars02 ycyars02 ydyars02 yeyars02 yfyars02 gender ; run; %impute(name=ivesetup3, dir=C:\Documents and Settings\gillian raab\My Documents\aprojects\peaslaptop\ex6datafiles\program_code ,setup=new); title Multiple imputation prevalence only; datain temp; dataout imp5 all ; default categorical; multiples 10; print coef; transfer caseid ; seed 1238; run ; /*---------------------------- next group--------------------*/ data temp; set ex6.ex6detail; keep caseid ycyrab02 ydyrab02 yeyrab02 yfyrab02 gender ; run; %impute(name=ivesetup3, dir=C:\Documents and Settings\gillian raab\My Documents\aprojects\peaslaptop\ex6datafiles\program_code ,setup=new); title Multiple imputation prevalence only; datain temp; dataout imp6 all ; default categorical; multiples 10; print coef; transfer caseid ; seed 1988; run ; /*---------------------------- next group--------------------*/ data temp; set ex6.ex6detail; keep caseid yayhbk02 ybyhbk02 ycyhbk02 ydyhbk02 yeyhbk02 yfyhbk02 ycyrob02 ydyrob02 yeyrob02 yfyrob02 gender ; run; %impute(name=ivesetup3, dir=C:\Documents and Settings\gillian raab\My Documents\aprojects\peaslaptop\ex6datafiles\program_code ,setup=new); title Multiple imputation prevalence only; datain temp; dataout imp7 all ; default categorical; multiples 10; print coef; transfer caseid ; seed 16709; run ; /*---------------------------- next group--------------------*/ data temp; set ex6.ex6detail; keep caseid ybypet02 ycypet02 ydypet02 yeypet02 yfypet02 gender ; run; %impute(name=ivesetup3, dir=C:\Documents and Settings\gillian raab\My Documents\aprojects\peaslaptop\ex6datafiles\program_code ,setup=new); title Multiple imputation prevalence only; datain temp; dataout imp8 all ; default categorical; multiples 10; print coef; transfer caseid ; seed 1338; run ; /*---------------------------- next group--------------------*/ data temp; set ex6.ex6detail; keep caseid yaybop02 ybybop02 ycybop02 ydybop02 yeybop02 yfybop02 gender ; run; %impute(name=ivesetup3, dir=C:\Documents and Settings\gillian raab\My Documents\aprojects\peaslaptop\ex6datafiles\program_code ,setup=new); title Multiple imputation prevalence only; datain temp; dataout imp9 all ; default categorical; multiples 10; print coef; transfer caseid ; seed 13568; run ; /*---------------------------- now calculate prevalence etc from the imputed data----------*/ data ex6.fromdetail (keep=dprev: dvol: dvar: caseid gender _mult_); set ex6.detailimp; /*---------------------------- sweep 1---------------------------------------*/ *Variety of delinquency at sweep one (n=15); array offv1 yaybus02 yaybop02 yayshp02 yayjrd02 yayscl02 yaywep02 yaygrf02 yayrob02 yayvnd02 yayhbk02 yayhom02 yaycbk02 yayars02 yayhit02 yayskv02; dprev1=0; dvar1=0; dvol1=0; do i=1 to 15; if offv1[i]>0 then do dprev1=1; dvar1=dvar1+1; end; if offv1[i]=7 then offv1[i]=11; * code to match SPSS; dvol1=offv1[i]+dvol1; ; end; /*---------------------------- sweep 2---------------------------------------*/ *Variety of delinquency at sweep two (n=16); array offv2 ybybus02 ybybop02 ybyshp02 ybyjrd02 ybyscl02 ybywep02 ybygrf02 ybyrob02 ybyvnd02 ybyhbk02 ybyhom02 ybycbk02 ybyars02 ybyhit02 ybyskv02 ybypet02 ; dprev2=0; dvar2=0; dvol2=0; do i=1 to 16; if offv2[i]>0 then do dprev2=1; dvar2=dvar2+1; end; if offv2[i]=7 then offv2[i]=11; * code to match SPSS; dvol2=offv2[i]+dvol2; end; /*---------------------------- sweep 3---------------------------------------*/ *Variety of delinquency at sweep three (n=18); array offv3 ycybus02 ycybop02 ycyshp02 ycyjrd02 ycyscl02 ycywep02 ycygrf02 ycyrob02 ycyvnd02 ycyhbk02 ycyhom02 ycycbk02 ycyars02 ycyhit02 ycyskv02 ycypet02 ycydrg02 ycyrab02 ; dprev3=0; dvar3=0; dvol3=0; do i=1 to 18; if offv3[i]>0 then do dprev3=1; dvar3=dvar3+1; end; if offv3[i]=7 then offv3[i]=11; * code to match SPSS; dvol3=offv3[i]+dvol3; end; /*---------------------------- sweep 4---------------------------------------*/ *Variety of delinquency at sweep three (n=18); array offv4 ydybus02 ydybop02 ydyshp02 ydyjrd02 ydyscl02 ydywep02 ydygrf02 ydyrob02 ydyvnd02 ydyhbk02 ydyhom02 ydycbk02 ydyars02 ydyhit02 ydyskv02 ydypet02 ydydrg02 ydyrab02; dprev4=0; dvar4=0; dvol4=0; do i=1 to 18; if offv4[i]>0 then do dprev4=1; dvar4=dvar4+1; end; if offv4[i]=7 then offv4[i]=11; * code to match SPSS; dvol4=offv4[i]+dvol4; end; /*---------------------------- sweep 5---------------------------------------*/ *Variety of delinquency at sweep five (n=17); array offv5 yeybus02 yeybop02 yeyshp02 yeyjrd02 yeywep02 yeygrf02 yeyrob02 yeyvnd02 yeyhbk02 yeycbk02 yeyars02 yeyhit02 yeyskv02 yeypet02 yeydrg02 yeyrab02 yeyrst02; dprev5=0; dvar5=0; dvol5=0; do i=1 to 17; if offv5[i]>0 then do dprev5=1; dvar5=dvar5+1; end; if offv5[i]=7 then offv5[i]=11; * code to match SPSS; dvol5=offv5[i]+dvol5; end; /*---------------------------- sweep 6---------------------------------------*/ *Variety of delinquency at sweep six (n=18); array offv6 yfybop02 yfyshp02 yfyjrd02 yfywep02 yfyrob02 yfyvnd02 yfyhbk02 yfycbk02 yfyars02 yfyhit02 yfypet02 yfyskv02 yfydrg02 yfyrab02 yfyrst02 yfyrst22 yfybft02 yfyfrd02; dprev6=0; dvar6=0; dvol6=0; do i=1 to 18; if offv6[i]>0 then do dprev6=1; dvar6=dvar6+1; end; if offv6[i]=7 then offv6[i]=11; * code to match SPSS; dvol6=offv6[i]+dvol6; end; run; /*----now merge this with some variables from the original file-----*/ data temp1; set ex6.ex6; keep caseid sector szindep; run; proc sort data=ex6.fromdetail ; by caseid;run; proc sort data=temp1 by caseid;run; data ex6.fromdetail; merge ex6.fromdetail temp1; by caseid; rename _Mult_ =_imputation_; * to use proc MI; run; /*----------------------------------------------------------------------------------- POST IMPUTATION PROCEDURES The imputation variable needs to be called _imputation_ renamed above These are always 2 stage procedures -------------------------------------------------------------------------------------*/ proc sort data=ex6.fromdetail; by _imputation_; run; proc means data=ex6.fromdetail; var dprev6 dvol6 dvar6; by _imputation_; run; /*proc freq data=ex6.detailimp; /*table yaywep02 ybywep02 ycywep02 ydywep02 yeywep02 yfywep02 ycydrg02 ydydrg02 yeydrg02 yfydrg02 yayhit02 ybyhit02 ycyhit02 ydyhit02 yeyhit02 yfyhit02 yayvnd02 ybyvnd02 ycyvnd02 ydyvnd02 yeyvnd02 yfyvnd02 yaygrf02 ybygrf02 ycygrf02 ydygrf02 yeygrf02 gender yayars02 ybyars02 ycyars02 ydyars02 yeyars02 yfyars02 ycyrab02 ydyrab02 yeyrab02 yfyrab02 yayhbk02 ybyhbk02 ycyhbk02 ydyhbk02 yeyhbk02 yfyhbk02 ycyrob02 ydyrob02 yeyrob02 yfyrob02 ybypet02 ycypet02 ydypet02 yeypet02 yfypet02 yaybop02 ybybop02 ycybop02 ydybop02 yeybop02 yfybop02; table yaybus02 ybybus02 ycybus02 ydybus02 yeybus02 yayskv02 ybyskv02 ycyskv02 ydyskv02 yeyskv02 yfyskv02 yeyrst02 yfyrst02 yfyrst22 yfybft02 yfyfrd02 yayshp02 ybyshp02 ycyshp02 ydyshp02 yeyshp02 yfyshp02 yayscl02 ybyscl02 ycyscl02 ydyscl02 yayhom02 ybyhom02 ycyhom02 ydyhom02 yaycbk02 ybycbk02 ycycbk02 ydycbk02 yeycbk02 yfycbk02 yayjrd02 ybyjrd02 ycyjrd02 ydyjrd02 yeyjrd02 yfyjrd02 yayrob02 ybyrob02; ; run;*/ /*---------------------------- get means using corr--------------------------------*/ PROC CORR DATA=ex6.fromdetail COV OUT=OUTCOV(TYPE=COV) NOCORR noprint ; VAR dprev1-dprev6 dvol1-dvol6 dvar1-dvar6 ; BY _IMPUTATION_; run; PROC MIANALYZE data=outcov ; VAR dprev1-dprev6 dvol1-dvol6 dvar1-dvar6 ; RUN; /*------------------- logistic regression and MIANALYZE---------------------------*/ proc logistic data=ex6.fromdetail outest=outreg covout descending noprint; by _imputation_; class gender szindep sector; model dprev6= gender szindep sector ; run; proc contents data= outreg short;run;* use this to find names of contrasts; PROC MIANALYZE data=outreg edf=4325 ; * these are the residual degrees of freedom from the model; var GENDERFemale SZINDEPManual_high_depr sectorBehavioural sectorIndependent sectorSpecial ; run; /*--We can compare with the complete data analysis here---------*/ proc logistic data=ex6.ex6 descending ; class gender szindep sector; model dprev6= gender szindep sector ; run; /*---------------- now a check to compare prevalence by deprivation with original data---*/ proc means data=ex6.fromdetail; class szindep; var dprev6; run; proc means data=ex6.ex6; class szindep; var dprev6; run; /*------------------------------------------------------------ Now analyses with proc MI that assume all variables are multivariate normal. Upper bounds are set on all variables to prevent high values But lower bounds are not set because experience showed that this resulted in a downward bias that gave too few responses in the zero category ---------------------------------------------------------------*/ proc contents short data=ex6.ex6detail; * this just to get list of variables; run; data temp1; set ex6.ex6detail; keep yaybus02 ybybus02 ycybus02 ydybus02 yeybus02 yayskv02 ybyskv02 ycyskv02 ydyskv02 yeyskv02 yfyskv02 yeyrst02 yfyrst02 yfyrst22 yfybft02 yfyfrd02 yayshp02 ybyshp02 ycyshp02 ydyshp02 yeyshp02 yfyshp02 yayscl02 ybyscl02 ycyscl02 ydyscl02 yayhom02 ybyhom02 ycyhom02 ydyhom02 yaycbk02 ybycbk02 ycycbk02 ydycbk02 yeycbk02 yfycbk02 yayjrd02 ybyjrd02 ycyjrd02 ydyjrd02 yeyjrd02 yfyjrd02 yayrob02 ybyrob02 gender; run; proc mi data=temp1 OUT=imp1 nimpute=10 round=1; VAR yaybus02 ybybus02 ycybus02 ydybus02 yeybus02 yayskv02 ybyskv02 ycyskv02 ydyskv02 yeyskv02 yfyskv02 yeyrst02 yfyrst02 yfyrst22 yfybft02 yfyfrd02 yayshp02 ybyshp02 ycyshp02 ydyshp02 yeyshp02 yfyshp02 yayscl02 ybyscl02 ycyscl02 ydyscl02 yayhom02 ybyhom02 ycyhom02 ydyhom02 yaycbk02 ybycbk02 ycycbk02 ydycbk02 yeycbk02 yfycbk02 yayjrd02 ybyjrd02 ycyjrd02 ydyjrd02 yeyjrd02 yfyjrd02 yayrob02 ybyrob02 gender ; RUN; /*---------- run this to check for extreme values--------*/ proc means data=imp1; run; /*---- now pull values <0 or >7 into range------------*/ data imp1; set imp1; array vars caseid yaybus02 ybybus02 ycybus02 ydybus02 yeybus02 yayskv02 ybyskv02 ycyskv02 ydyskv02 yeyskv02 yfyskv02 yeyrst02 yfyrst02 yfyrst22 yfybft02 yfyfrd02 yayshp02 ybyshp02 ycyshp02 ydyshp02 yeyshp02 yfyshp02 yayscl02 ybyscl02 ycyscl02 ydyscl02 yayhom02 ybyhom02 ycyhom02 ydyhom02 yaycbk02 ybycbk02 ycycbk02 ydycbk02 yeycbk02 yfycbk02 yayjrd02 ybyjrd02 ycyjrd02 ydyjrd02 yeyjrd02 yfyjrd02 yayrob02 ybyrob02 ; do over vars; if vars<0 then vars=0; if vars>7 then vars=7; end; run; data temp2; set ex6.ex6detail; keep caseid yaywep02 ybywep02 ycywep02 ydywep02 yeywep02 yfywep02 ycydrg02 ydydrg02 yeydrg02 yfydrg02 yayhit02 ybyhit02 ycyhit02 ydyhit02 yeyhit02 yfyhit02 yayvnd02 ybyvnd02 ycyvnd02 ydyvnd02 yeyvnd02 yfyvnd02 yaygrf02 ybygrf02 ycygrf02 ydygrf02 yeygrf02 gender yayars02 ybyars02 ycyars02 ydyars02 yeyars02 yfyars02 ycyrab02 ydyrab02 yeyrab02 yfyrab02 yayhbk02 ybyhbk02 ycyhbk02 ydyhbk02 yeyhbk02 yfyhbk02 ycyrob02 ydyrob02 yeyrob02 yfyrob02 ybypet02 ycypet02 ydypet02 yeypet02 yfypet02 yaybop02 ybybop02 ycybop02 ydybop02 yeybop02 yfybop02 gender; run; proc mi data=temp2 OUT=imp2 nimpute=10 round=1; VAR yaywep02 ybywep02 ycywep02 ydywep02 yeywep02 yfywep02 ycydrg02 ydydrg02 yeydrg02 yfydrg02 yayhit02 ybyhit02 ycyhit02 ydyhit02 yeyhit02 yfyhit02 yayvnd02 ybyvnd02 ycyvnd02 ydyvnd02 yeyvnd02 yfyvnd02 yaygrf02 ybygrf02 ycygrf02 ydygrf02 yeygrf02 gender yayars02 ybyars02 ycyars02 ydyars02 yeyars02 yfyars02 ycyrab02 ydyrab02 yeyrab02 yfyrab02 yayhbk02 ybyhbk02 ycyhbk02 ydyhbk02 yeyhbk02 yfyhbk02 ycyrob02 ydyrob02 yeyrob02 yfyrob02 ybypet02 ycypet02 ydypet02 yeypet02 yfypet02 yaybop02 ybybop02 ycybop02 ydybop02 yeybop02 yfybop02 gender ; RUN; proc means data=imp2; run; /*---- now pull values <0 or >7 into range------------*/ data imp2; set imp2; array vars yaywep02 ybywep02 ycywep02 ydywep02 yeywep02 yfywep02 ycydrg02 ydydrg02 yeydrg02 yfydrg02 yayhit02 ybyhit02 ycyhit02 ydyhit02 yeyhit02 yfyhit02 yayvnd02 ybyvnd02 ycyvnd02 ydyvnd02 yeyvnd02 yfyvnd02 yaygrf02 ybygrf02 ycygrf02 ydygrf02 yeygrf02 gender yayars02 ybyars02 ycyars02 ydyars02 yeyars02 yfyars02 ycyrab02 ydyrab02 yeyrab02 yfyrab02 yayhbk02 ybyhbk02 ycyhbk02 ydyhbk02 yeyhbk02 yfyhbk02 ycyrob02 ydyrob02 yeyrob02 yfyrob02 ybypet02 ycypet02 ydypet02 yeypet02 yfypet02 yaybop02 ybybop02 ycybop02 ydybop02 yeybop02 yfybop02; do over vars; if vars<0 then vars=0; if vars>7 then vars=7; end; run; proc freq data=imp2; * checking this one since it had some very high imputed values; table _imputation_ *yeybop02/nopercent nocol; run; proc freq data=ex6.ex6detail; table yeybop02; run; /*------- now merge two imputed data sets togther--------*/ data ex6.detailimpmi; merge imp1 imp2; run; /*---------------------------- now calculate prevalence etc from the imputed data----------*/ data ex6.fromdetailmi (keep=dprev: dvol: dvar: caseid gender _imputation_); set ex6.detailimpmi; /*---------------------------- sweep 1---------------------------------------*/ *Variety of delinquency at sweep one (n=15); array offv1 yaybus02 yaybop02 yayshp02 yayjrd02 yayscl02 yaywep02 yaygrf02 yayrob02 yayvnd02 yayhbk02 yayhom02 yaycbk02 yayars02 yayhit02 yayskv02; dprev1=0; dvar1=0; dvol1=0; do i=1 to 15; if offv1[i]>0 then do dprev1=1; dvar1=dvar1+1; end; if offv1[i]=7 then offv1[i]=11; * code to match SPSS; dvol1=offv1[i]+dvol1; ; end; /*---------------------------- sweep 2---------------------------------------*/ *Variety of delinquency at sweep two (n=16); array offv2 ybybus02 ybybop02 ybyshp02 ybyjrd02 ybyscl02 ybywep02 ybygrf02 ybyrob02 ybyvnd02 ybyhbk02 ybyhom02 ybycbk02 ybyars02 ybyhit02 ybyskv02 ybypet02 ; dprev2=0; dvar2=0; dvol2=0; do i=1 to 16; if offv2[i]>0 then do dprev2=1; dvar2=dvar2+1; end; if offv2[i]=7 then offv2[i]=11; * code to match SPSS; dvol2=offv2[i]+dvol2; end; /*---------------------------- sweep 3---------------------------------------*/ *Variety of delinquency at sweep three (n=18); array offv3 ycybus02 ycybop02 ycyshp02 ycyjrd02 ycyscl02 ycywep02 ycygrf02 ycyrob02 ycyvnd02 ycyhbk02 ycyhom02 ycycbk02 ycyars02 ycyhit02 ycyskv02 ycypet02 ycydrg02 ycyrab02 ; dprev3=0; dvar3=0; dvol3=0; do i=1 to 18; if offv3[i]>0 then do dprev3=1; dvar3=dvar3+1; end; if offv3[i]=7 then offv3[i]=11; * code to match SPSS; dvol3=offv3[i]+dvol3; end; /*---------------------------- sweep 4---------------------------------------*/ *Variety of delinquency at sweep three (n=18); array offv4 ydybus02 ydybop02 ydyshp02 ydyjrd02 ydyscl02 ydywep02 ydygrf02 ydyrob02 ydyvnd02 ydyhbk02 ydyhom02 ydycbk02 ydyars02 ydyhit02 ydyskv02 ydypet02 ydydrg02 ydyrab02; dprev4=0; dvar4=0; dvol4=0; do i=1 to 18; if offv4[i]>0 then do dprev4=1; dvar4=dvar4+1; end; if offv4[i]=7 then offv4[i]=11; * code to match SPSS; dvol4=offv4[i]+dvol4; end; /*---------------------------- sweep 5---------------------------------------*/ *Variety of delinquency at sweep five (n=17); array offv5 yeybus02 yeybop02 yeyshp02 yeyjrd02 yeywep02 yeygrf02 yeyrob02 yeyvnd02 yeyhbk02 yeycbk02 yeyars02 yeyhit02 yeyskv02 yeypet02 yeydrg02 yeyrab02 yeyrst02; dprev5=0; dvar5=0; dvol5=0; do i=1 to 17; if offv5[i]>0 then do dprev5=1; dvar5=dvar5+1; end; if offv5[i]=7 then offv5[i]=11; * code to match SPSS; dvol5=offv5[i]+dvol5; end; /*---------------------------- sweep 6---------------------------------------*/ *Variety of delinquency at sweep six (n=18); array offv6 yfybop02 yfyshp02 yfyjrd02 yfywep02 yfyrob02 yfyvnd02 yfyhbk02 yfycbk02 yfyars02 yfyhit02 yfypet02 yfyskv02 yfydrg02 yfyrab02 yfyrst02 yfyrst22 yfybft02 yfyfrd02; dprev6=0; dvar6=0; dvol6=0; do i=1 to 18; if offv6[i]>0 then do dprev6=1; dvar6=dvar6+1; end; if offv6[i]=7 then offv6[i]=11; * code to match SPSS; dvol6=offv6[i]+dvol6; end; run; /*----now merge this with some variables from the original file-----*/ data temp1; set ex6.ex6; keep caseid sector szindep; run; proc sort data=ex6.fromdetailmi ; by caseid;run; proc sort data=temp1; by caseid;run; data ex6.fromdetailmi; merge ex6.fromdetailmi temp1; by caseid; run; /*----------------------------------------------------------------------------------- POST IMPUTATION PROCEDURES The imputation variable needs to be called _imputation_ renamed above These are always 2 stage procedures -------------------------------------------------------------------------------------*/ proc sort data=ex6.fromdetailmi; by _imputation_; run; /*---------------------------- get means using corr--------------------------------*/ PROC CORR DATA=ex6.fromdetailmi COV OUT=OUTCOV(TYPE=COV) NOCORR noprint ; VAR dprev1-dprev6 dvol1-dvol6 dvar1-dvar6 ; where gender=1; * boys only; BY _IMPUTATION_; run; PROC MIANALYZE data=outcov ; title 'MI detailed imputation boys'; VAR dprev1-dprev6 dvol1-dvol6 dvar1-dvar6 ; RUN; PROC CORR DATA=ex6.fromdetailmi COV OUT=OUTCOV(TYPE=COV) NOCORR noprint ; VAR dprev1-dprev6 dvol1-dvol6 dvar1-dvar6 ; where gender=2; * girls only; BY _IMPUTATION_; run; PROC MIANALYZE data=outcov ; title 'MI detailed imputation girls'; VAR dprev1-dprev6 dvol1-dvol6 dvar1-dvar6 ; RUN; /*------------------- logistic regression and MIANALYZE---------------------------*/ proc logistic data=ex6.fromdetailmi outest=outreg covout descending noprint; by _imputation_; class gender szindep sector; model dprev6= gender szindep sector ; run; proc contents data= outreg short;run;* use this to find names of contrasts; PROC MIANALYZE data=outreg edf=4325 ; * these are the residual degrees of freedom from the model; var GENDER1 SZINDEPManual_high_depr sectorBehavioural sectorIndependent sectorSpecial ; run; /*--We can compare with the complete data analysis here---------*/ proc logistic data=ex6.ex6 descending ; class gender szindep sector; model dprev6= gender szindep sector ; run; /*---------------- now a check to compare prevalence by deprivation with original data---*/ proc means data=ex6.fromdetail; class szindep; var dprev6; run; proc means data=ex6.ex6; /**************************************************************************************************************************************** Imputation SAS code for Exemplar 6 THESE ARE TRIALS THAT DID NOT WORK The output from the program showed this in all cases, but it needed to be checked through carefully. ALSO to run the IVEWARE software you need to close all advanced editor windows and use only the old program editor CHANGE the libname to shere your data sets are stored proc contents data=ex6.ex6DETAIL short position;run; ****************************************************************************************************************************************/ libname ex6 'C:\Documents and Settings\gillian raab\My Documents\aprojects\peaslaptop\ex6datafiles\data' ; /*------------------------------------------------------------------ Now the analysis of detailed questions using the IVEWARE macros details of what the commands mean are in the user guide on the IVE site. --------------------------------------------------------------------*/ title 'Imputation of detailed questions with IVEWARE'; /*------------------------------------------------------------------- Notes on IVEWARE trials on detailed questions that did not work 1 Defining the variables as CATEGORICAL with 8 classes (0 to 7) was too big a program to be be able to include all variables. Restricting to a maximum of 10 predictors seemed to work OK despite some warning messages until I noticed that some sparse questions had imputed to give almost all the missing data to the highest category. 2. Then tried dividing them into subgroups. But this could have just the same problems especially for sparse variables. 3 Defining variables as MIXED (0 plus regression for those with events) with no bounds gave many huge values + or -ve so all either 0 or 7 when truncated 4 MIXED variables with <=7 gave either all imputed at 7 or all at zero (once rounded etc) 5 MIXED with both bounds on gave almost everything predicted to zeros 6 Restricting to 10 predictors helped a bit but still several variables going to all zeros or all 1s 7 Defining a COUNT variable with no limits pulling the highest values back to 7 gave rather too many in the highest category, though it seemed not bad. 8 Counts with limits <=7 seemed even better will try this a bit more. This is in the program EX6DET.SAS The code for each of these efforts is given below -----------------------------------------------------------------------*/ /*------------------------------------------------------------------- Attempt 1 This took almost a day, so don't try it unless you are about to go away for a bit. And it only worked afer various preliminary investigations that set the stepwise procedures to have a max of 10 variables and to stop the iterations at 10, which is a bit dodgy. It does give warnings. Otherwise it would have taken months -----------------------------------------------------------------------*/ %impute(name=ivesetup3, dir=C:\Documents and Settings\gillian raab\My Documents\aprojects\peaslaptop\ex6datafiles\program_code ,setup=new); title Attempt one all categorical; datain EX6.ex6DETAIL; dataout imp1 all ; default categorical; transfer caseid ; maxpred 10; maxlogi 10; iterations 5; multiples 5; seed 1768; run ; /*---------------------------------------------------------------- Attempt 2 Smaller categorical model This one fails too in a similar way to 1 and takes less time. ------------------------------------------------------------------*/ data temp; set ex6.ex6det; keep caseid yayars02 ybyars02 ycyars02 ydyars02 yeyars02 yfyars02 gender ; run; %impute(name=ivesetup3, dir=C:\Documents and Settings\gillian raab\My Documents\aprojects\peaslaptop\ex6datafiles\program_code ,setup=new); title Multiple imputation detailed questions (subsets) categorical; datain temp; dataout imp2 all ; default categorical; maxlogi 50; iterations 5; multiples 1; transfer caseid ; print coef; run ; /*---------------------------------------------------------------- Attempt 2 Mixed (zeros and normal when non-zero) . ------------------------------------------------------------------*/ %impute(name=ivesetup3, dir=C:\Documents and Settings\gillian raab\My Documents\aprojects\peaslaptop\ex6datafiles\program_code ,setup=new); title Attempt one all categorical; datain EX6.ex6DETAIL; dataout imp3 all ; default mixed; transfer caseid ; iterations 5; multiples 1; seed 1768; run ; data imp3; set imp3; * need to sort out data after; array all _numeric_; gender=100+gender; * so that this 1/2 var is not affected; do over all; all=round(all); if all<0 then all=0; if all>7 and all<100 then all=7; gender=gender-100; end; run; %checkimp(imp3,ex6.ex6det); %impute(name=ivesetup3, dir=C:\Documents and Settings\gillian raab\My Documents\aprojects\peaslaptop\ex6datafiles\program_code ,setup=new); title Multiple imputation prevalence only; datain ex6.ex6det; dataout impout all ; default count; bounds YAYARS02(>0,<=7) YAYBOP02(>0,<=7)YAYBUS02(>0,<=7) YAYCBK02(>0,<=7) YAYGRF02(>0,<=7) YAYHBK02(>0,<=7) YAYHIT02(>0,<=7) YAYHOM02(>0,<=7) YAYJRD02(>0,<=7) YAYROB02(>0,<=7) YAYSCL02(>0,<=7) YAYSHP02(>0,<=7) YAYSKV02(>0,<=7) YAYVND02(>0,<=7) YAYWEP02(>0,<=7) YBYARS02(>0,<=7) YBYBOP02(>0,<=7) YBYBUS02(>0,<=7) YBYCBK02(>0,<=7) YBYGRF02(>0,<=7) YBYHBK02(>0,<=7) YBYHIT02(>0,<=7) YBYHOM02(>0,<=7) YBYJRD02(>0,<=7) YBYPET02(>0,<=7) YBYROB02(>0,<=7) YBYSCL02(>0,<=7) YBYSHP02(>0,<=7) YBYSKV02(>0,<=7) YBYVND02(>0,<=7) YBYWEP02(>0,<=7) YCYARS02(>0,<=7) YCYBOP02(>0,<=7) YCYBUS02(>0,<=7) YCYCBK02(>0,<=7) YCYDRG02(>0,<=7) YCYGRF02(>0,<=7) YCYHBK02(>0,<=7) YCYHIT02(>0,<=7) YCYHOM02(>0,<=7) YCYJRD02(>0,<=7) YCYPET02(>0,<=7) YCYRAB02(>0,<=7) YCYROB02(>0,<=7) YCYSCL02(>0,<=7) YCYSHP02(>0,<=7) YCYSKV02(>0,<=7) YCYVND02(>0,<=7) YCYWEP02(>0,<=7) YDYARS02(>0,<=7) YDYBOP02(>0,<=7) YDYBUS02(>0,<=7) YDYCBK02(>0,<=7) YDYDRG02(<=7) YDYGRF02(<=7) YDYHBK02(>0,<=7) YDYHIT02(>0,<=7) YDYHOM02(>0,<=7) YDYJRD02(>0,<=7) YDYPET02(>0,<=7) YDYRAB02(>0,<=7) YDYROB02(>0,<=7) YDYSCL02(>0,<=7) YDYSHP02(>0,<=7) YDYSKV02(>0,<=7) YDYVND02(>0,<=7) YDYWEP02(>0,<=7) YEYARS02(>0,<=7) YEYBOP02(>0,<=7) YEYBUS02(>0,<=7) YEYCBK02(>0,<=7) YEYDRG02(>0,<=7) YEYGRF02(>0,<=7) YEYHBK02(>0,<=7) YEYHIT02(>0,<=7) YEYJRD02(>0,<=7) YEYPET02(>0,<=7) YEYRAB02(>0,<=7) YEYROB02(>0,<=7) YEYRST02(>0,<=7) YEYSHP02(>0,<=7) YEYSKV02(>0,<=7) YEYVND02(>0,<=7) YEYWEP02(>0,<=7) YFYARS02(>0,<=7) YFYBFT02(>0,<=7) YFYBOP02(>0,<=7) YFYCBK02(>0,<=7) YFYDRG02(>0,<=7) YFYFRD02(>0,<=7) YFYHBK02(>0,<=7) YFYHIT02(>0,<=7) YFYJRD02(>0,<=7) YFYPET02(>0,<=7) YFYRAB02(>0,<=7) YFYROB02(>0,<=7) YFYRST02(>0,<=7) YFYRST22(>0,<=7) YFYSHP02(>0,<=7) YFYSKV02(>0,<=7) YFYVND02(>0,<=7) YFYWEP02(>0,<=7); iterations 5; multiples 5; transfer caseid ; run ;