/* file to set up libnames, fmt/mac locations */ %include "../../../fem_env.sas"; libname bio "&dua_rand_hrs"; %let seed=1230543890; /*options obs=20000; */ *** Step 1 - Assign the value for hdl_onewave = 1, from the donor pool (hdl_twowaves = 1) *** Step 2 - Assign the value for hdl_nowave = 1, from the donor pool (hdl_twowaves = 1) *** Things need to do before this - 1. Re-create the appropriate grouping variables and add it in the sql step *** 3. Reshape the data to wide form (hhidpn wave pct_* hearte hibpe diabe rxchol) **%macro imp (bio, pctbio, pctbiohat, pctbiosd, imppctbio, impflag); proc import out=bio.bio_imp20tiles_wide datafile="&dua_rand_hrs./bio_imp20tiles_wide.dta"; run; proc import out=bio.bio_hrs_recoded_prepimp_v1 datafile="&dua_rand_hrs./bio_hrs_recoded_prepimp_v1.dta"; run; proc print data=bio.bio_imp20tiles_wide (where=(hhidpn in (10537011 11802011))); run; /*************************************************; ** HDL; *************************************************;*/ /* select stddev(pct_a1c_hat) into :a1c_sd from bio.fname; */ %macro sqlyr(yr,wv); proc sql; create table miss_donorhdl&yr as select a.hhidpn,&wv as hdl_nm_wave,a.pct_hdl_hat&yr as pct_hdl_hat,a.pct_hdl&yr as pct_hdl_nm,b.hhidpn as donor_id, b.pct_hdl_hat&yr as donorpct_hdl_hat, b.pct_hdl06 as donorpct_hdl06, b.pct_hdl08 as donorpct_hdl08, b.pct_hdl10 as donorpct_hdl10, b.pct_hdl12 as donorpct_hdl12, b.pct_hdl14 as donorpct_hdl14, abs(a.pct_hdl_hat&yr - b.pct_hdl_hat&yr) as distance from bio.bio_imp20tiles_wide (where=((hdl_onewave=1 or hdl_twowaves_sas=1) & pct_hdl&yr ne . and pct_hdl_hat&yr ne . )) a left join bio.bio_imp20tiles_wide (where=((hdl_threewaves=1 or hdl_twowaves_nosas=1) & pct_hdl&yr ne . and pct_hdl_hat&yr ne . )) b on a.pct_hdl&yr = b.pct_hdl&yr & (a.hearte06 = b.hearte06 or missing(a.hearte06) or missing(b.hearte06) ) & (a.hearte08 = b.hearte08 or missing(a.hearte08) or missing(b.hearte08) ) & (a.hearte10 = b.hearte10 or missing(a.hearte10) or missing(b.hearte10) ) & (a.hearte12 = b.hearte12 or missing(a.hearte12) or missing(b.hearte12) ) & (a.hearte14 = b.hearte14 or missing(a.hearte14) or missing(b.hearte14) ) /*& abs(a.pct_hdl_hat-b.pct_hdl_hat)<=(1.5*a.pct_hdl_sd) */ order a.hhidpn,calculated distance; create table no_donorhdl&yr as select b.* from miss_donorhdl&yr (where=(donor_id = .)) a left join bio.bio_imp20tiles_wide b on a.hhidpn = b.hhidpn ; create table miss_donorhdl_nd&yr as select a.hhidpn,&wv as hdl_nm_wave,a.pct_hdl_hat&yr as pct_hdl_hat,a.pct_hdl&yr as pct_hdl_nm,b.hhidpn as donor_id, b.pct_hdl_hat&yr as donorpct_hdl_hat, b.pct_hdl06 as donorpct_hdl06, b.pct_hdl08 as donorpct_hdl08, b.pct_hdl10 as donorpct_hdl10, b.pct_hdl12 as donorpct_hdl12, b.pct_hdl14 as donorpct_hdl14, abs(a.pct_hdl_hat&yr - b.pct_hdl_hat&yr) as distance from no_donorhdl&yr (where=((hdl_onewave=1 or hdl_twowaves_sas=1) & pct_hdl&yr ne . and pct_hdl_hat&yr ne . )) a left join bio.bio_imp20tiles_wide (where=((hdl_threewaves=1 or hdl_twowaves_nosas=1) & pct_hdl&yr ne . and pct_hdl_hat&yr ne . )) b on a.pct_hdl&yr = b.pct_hdl&yr /* & abs(a.pct_hdl_hat&yr-b.pct_hdl_hat&yr)<=(1.5*a.pct_hdl_sd&yr) */ order a.hhidpn,calculated distance; data miss_donorhdl&yr ; merge miss_donorhdl&yr miss_donorhdl_nd&yr ; by hhidpn ; run; %mend; %sqlyr(06,8) %sqlyr(08,9) %sqlyr(10,10) %sqlyr(12,11) %sqlyr(14,12) proc sql; create table miss_donorhdl as select a.hhidpn,0 as hdl_nm_wave, a.pct_hdl_hat,b.pct_hdl_hat as donorpct_hdl_hat,b.hhidpn as donor_id, b.pct_hdl06 as donorpct_hdl06, b.pct_hdl08 as donorpct_hdl08, b.pct_hdl10 as donorpct_hdl10, b.pct_hdl12 as donorpct_hdl12, b.pct_hdl14 as donorpct_hdl14, abs(a.pct_hdl_hat-b.pct_hdl_hat) as distance from bio.bio_imp20tiles_wide (where=(hdl_nowave=1 and pct_hdl_hat ne . )) a left join bio.bio_imp20tiles_wide (where=((hdl_threewaves=1 or hdl_twowaves_nosas=1) and pct_hdl_hat ne . )) b on (a.hearte06 = b.hearte06 or missing(a.hearte06) or missing(b.hearte06) ) & (a.hearte08 = b.hearte08 or missing(a.hearte08) or missing(b.hearte08) ) & (a.hearte10 = b.hearte10 or missing(a.hearte10) or missing(b.hearte10) ) & (a.hearte12 = b.hearte12 or missing(a.hearte12) or missing(b.hearte12) ) & (a.hearte14 = b.hearte14 or missing(a.hearte14) or missing(b.hearte14) ) /* & abs(a.pct_hdl_hat-b.pct_hdl_hat)<=(1.5*a.pct_hdl_sd) */ order a.hhidpn,calculated distance; proc print data=miss_donorhdl06 (obs=200); run; proc print data=miss_donorhdl10 (where=(donor_id=.) obs=100); title2 donor id missing ; run; title2 selected cases; proc print data=miss_donorhdl (obs=200); run; /* only keep 10 in the donor pool */ data setup checknhdl; set miss_donorhdl miss_donorhdl06 miss_donorhdl08 miss_donorhdl10 miss_donorhdl12 miss_donorhdl14; by hdl_nm_wave hhidpn ; retain n_donor; if first.hhidpn then n_donor=0; n_donor=n_donor+1; if last.hhidpn then do; if n_donor>=10 then n_donor_status=3; else if n_donor>=5 then n_donor_status=2; else if n_donor>0 then n_donor_status=1; else n_donor_status=0; output checknhdl; end; /* if one of the candidate donors then assign random number and output */ if n_donor<=10 then do; ran_num=ranuni(&seed); output setup; end; run; proc print data=checknhdl (obs=200) ; run; proc means data=checknhdl; class n_donor_status; var n_donor; run; /*proc print data=checkn&bio (where=(n_donor<5) obs=20); title2 hhidpn-wave with fewer than 5 donors; run; title2; */ proc sort data=setup; by hdl_nm_wave hhidpn ran_num; data imputedhdl; set setup; by hdl_nm_wave hhidpn ; if first.hhidpn; * imp_pct_hdl=donorpct_hdl08; run; proc sort data=imputedhdl out=bio.imputedhdl; by hhidpn; proc print data=bio.imputedhdl (obs=100) ; run; data bio.bio_imp_finalhdl; merge bio.imputedhdl (in=_inimp keep=hhidpn donorpct_hdl: hdl_nm_wave) bio.bio_hrs_recoded_prepimp_v1 (in=_inpct) ; by hhidpn ; impflag2_hdl=_inimp; if missing(pct_hdl) and wave=8 then pct_hdl=donorpct_hdl06; if missing(pct_hdl) and wave=9 then pct_hdl=donorpct_hdl08; if missing(pct_hdl) and wave=10 then pct_hdl=donorpct_hdl10; if missing(pct_hdl) and wave=11 then pct_hdl=donorpct_hdl12; if missing(pct_hdl) and wave=12 then pct_hdl=donorpct_hdl14; if impflag2_hdl=1 and missing(pct_hdl)=1 then impflag2_hdl=9; run; proc contents data=bio.bio_imp_finalhdl; run; proc means data=bio.bio_imp_finalhdl; class impflag2_hdl; types () impflag2_hdl; var pct_hdl ; run; /*************************************************; ** TCHOL; *************************************************;*/ %macro sqlyr(yr,wv); proc sql; create table miss_donortchol&yr as select a.hhidpn,&wv as tchol_nm_wave,a.pct_tchol_hat&yr as pct_tchol_hat,a.pct_tchol&yr as pct_tchol_nm,b.hhidpn as donor_id, b.pct_tchol_hat&yr as donorpct_tchol_hat, b.pct_tchol06 as donorpct_tchol06, b.pct_tchol08 as donorpct_tchol08, b.pct_tchol10 as donorpct_tchol10, b.pct_tchol12 as donorpct_tchol12, b.pct_tchol14 as donorpct_tchol14, abs(a.pct_tchol_hat&yr - b.pct_tchol_hat&yr) as distance from bio.bio_imp20tiles_wide (where=((tchol_onewave=1 or tchol_twowaves_sas=1) & pct_tchol&yr ne . and pct_tchol_hat&yr ne . )) a left join bio.bio_imp20tiles_wide (where=((tchol_threewaves=1 or tchol_twowaves_nosas=1) & pct_tchol&yr ne . and pct_tchol_hat&yr ne . )) b on a.pct_tchol&yr = b.pct_tchol&yr & (a.rxchol06 = b.rxchol06 or missing(a.rxchol06) or missing(b.rxchol06) ) & (a.rxchol08 = b.rxchol08 or missing(a.rxchol08) or missing(b.rxchol08) ) & (a.rxchol10 = b.rxchol10 or missing(a.rxchol10) or missing(b.rxchol10) ) & (a.rxchol12 = b.rxchol12 or missing(a.rxchol12) or missing(b.rxchol12) ) & (a.rxchol14 = b.rxchol14 or missing(a.rxchol14) or missing(b.rxchol14) ) /* & abs(a.pct_tchol_hat&yr-b.pct_tchol_hat&yr)<=(1.5*a.pct_tchol_sd&yr) */ order a.hhidpn,calculated distance; create table no_donortchol&yr as select b.* from miss_donortchol&yr (where=(donor_id = .)) a left join bio.bio_imp20tiles_wide b on a.hhidpn = b.hhidpn ; create table miss_donortchol_nd&yr as select a.hhidpn,&wv as tchol_nm_wave,a.pct_tchol_hat&yr as pct_tchol_hat,a.pct_tchol&yr as pct_tchol_nm,b.hhidpn as donor_id, b.pct_tchol_hat&yr as donorpct_tchol_hat, b.pct_tchol06 as donorpct_tchol06, b.pct_tchol08 as donorpct_tchol08, b.pct_tchol10 as donorpct_tchol10, b.pct_tchol12 as donorpct_tchol12, b.pct_tchol14 as donorpct_tchol14, abs(a.pct_tchol_hat&yr - b.pct_tchol_hat&yr) as distance from no_donortchol&yr (where=((tchol_onewave=1 or tchol_twowaves_sas=1) & pct_tchol&yr ne . and pct_tchol_hat&yr ne . )) a left join bio.bio_imp20tiles_wide (where=((tchol_threewaves=1 or tchol_twowaves_nosas=1) & pct_tchol&yr ne . and pct_tchol_hat&yr ne . )) b on a.pct_tchol&yr = b.pct_tchol&yr /* & abs(a.pct_tchol_hat&yr-b.pct_tchol_hat&yr)<=(1.5*a.pct_tchol_sd&yr) */ order a.hhidpn,calculated distance; data miss_donortchol&yr ; merge miss_donortchol&yr miss_donortchol_nd&yr ; by hhidpn ; run; %mend; %sqlyr(06,8) %sqlyr(08,9) %sqlyr(10,10) %sqlyr(12,11) %sqlyr(14,12) proc sql; create table miss_donortchol as select a.hhidpn,0 as tchol_nm_wave, a.pct_tchol_hat,b.pct_tchol_hat as donorpct_tchol_hat,b.hhidpn as donor_id, b.pct_tchol06 as donorpct_tchol06, b.pct_tchol08 as donorpct_tchol08, b.pct_tchol10 as donorpct_tchol10, b.pct_tchol12 as donorpct_tchol12, b.pct_tchol14 as donorpct_tchol14, abs(a.pct_tchol_hat-b.pct_tchol_hat) as distance from bio.bio_imp20tiles_wide (where=(tchol_nowave=1 and pct_tchol_hat ne . )) a left join bio.bio_imp20tiles_wide (where=((tchol_threewaves=1 or tchol_twowaves_nosas=1) and pct_tchol_hat ne . )) b on (a.rxchol06 = b.rxchol06 or missing(a.rxchol06) or missing(b.rxchol06) ) & (a.rxchol08 = b.rxchol08 or missing(a.rxchol08) or missing(b.rxchol08) ) & (a.rxchol10 = b.rxchol10 or missing(a.rxchol10) or missing(b.rxchol10) ) & (a.rxchol12 = b.rxchol12 or missing(a.rxchol12) or missing(b.rxchol12) ) & (a.rxchol14 = b.rxchol14 or missing(a.rxchol14) or missing(b.rxchol14) ) /* & abs(a.pct_tchol_hat-b.pct_tchol_hat)<=(1.5*a.pct_tchol_sd) */ order a.hhidpn,calculated distance; proc print data=miss_donortchol06 (obs=200); run; proc print data=miss_donortchol10 (where=(donor_id=.) obs=100); title2 donor id missing ; run; title2 selected cases; proc print data=miss_donortchol (obs=200); run; /* only keep 10 in the donor pool */ data setup checkntchol; set miss_donortchol miss_donortchol06 miss_donortchol08 miss_donortchol10 miss_donortchol12 miss_donortchol14; by tchol_nm_wave hhidpn ; retain n_donor; if first.hhidpn then n_donor=0; n_donor=n_donor+1; if last.hhidpn then do; if n_donor>=10 then n_donor_status=3; else if n_donor>=5 then n_donor_status=2; else if n_donor>0 then n_donor_status=1; else n_donor_status=0; output checkntchol; end; /* if one of the candidate donors then assign random number and output */ if n_donor<=10 then do; ran_num=ranuni(&seed); output setup; end; run; proc print data=checkntchol (obs=200) ; run; proc means data=checkntchol; class n_donor_status; var n_donor; run; /*proc print data=checkn&bio (where=(n_donor<5) obs=20); title2 hhidpn-wave with fewer than 5 donors; run; title2; */ proc sort data=setup; by tchol_nm_wave hhidpn ran_num; data imputedtchol; set setup; by tchol_nm_wave hhidpn ; if first.hhidpn; * imp_pct_tchol=donorpct_tchol08; run; proc sort data=imputedtchol out=bio.imputedtchol; by hhidpn; proc print data=bio.imputedtchol (obs=100) ; run; data bio.bio_imp_finaltchol; merge bio.imputedtchol (in=_inimp keep=hhidpn donorpct_tchol: tchol_nm_wave) bio.bio_hrs_recoded_prepimp_v1 (in=_inpct) ; by hhidpn ; impflag2_tchol=_inimp; if missing(pct_tchol) and wave=8 then pct_tchol=donorpct_tchol06; if missing(pct_tchol) and wave=9 then pct_tchol=donorpct_tchol08; if missing(pct_tchol) and wave=10 then pct_tchol=donorpct_tchol10; if missing(pct_tchol) and wave=11 then pct_tchol=donorpct_tchol12; if missing(pct_tchol) and wave=12 then pct_tchol=donorpct_tchol14; if impflag2_tchol=1 and missing(pct_tchol)=1 then impflag2_tchol=9; run; proc contents data=bio.bio_imp_finaltchol; run; proc means data=bio.bio_imp_finaltchol; class impflag2_tchol; types () impflag2_tchol; var pct_tchol ; run; /*************************************************; ** HBA1c; *************************************************;*/ /* select stddev(pct_a1c_hat) into :a1c_sd from bio.fname; */ %macro sqlyr(yr,wv); proc sql; create table miss_donora1c&yr as select a.hhidpn,&wv as a1c_nm_wave,a.pct_a1c_hat&yr as pct_a1c_hat,a.pct_a1c&yr as pct_a1c_nm,b.hhidpn as donor_id, b.pct_a1c_hat&yr as donorpct_a1c_hat, b.pct_a1c06 as donorpct_a1c06, b.pct_a1c08 as donorpct_a1c08, b.pct_a1c10 as donorpct_a1c10, b.pct_a1c12 as donorpct_a1c12, b.pct_a1c14 as donorpct_a1c14, abs(a.pct_a1c_hat&yr - b.pct_a1c_hat&yr) as distance from bio.bio_imp20tiles_wide (where=((a1c_onewave=1 or a1c_twowaves_sas=1) & pct_a1c&yr ne . and pct_a1c_hat&yr ne . )) a left join bio.bio_imp20tiles_wide (where=((a1c_threewaves=1 or a1c_twowaves_nosas=1) & pct_a1c&yr ne . and pct_a1c_hat&yr ne . )) b on a.pct_a1c&yr = b.pct_a1c&yr & (a.diabe06 = b.diabe06 or missing(a.diabe06) or missing(b.diabe06) ) & (a.diabe08 = b.diabe08 or missing(a.diabe08) or missing(b.diabe08) ) & (a.diabe10 = b.diabe10 or missing(a.diabe10) or missing(b.diabe10) ) & (a.diabe12 = b.diabe12 or missing(a.diabe12) or missing(b.diabe12) ) & (a.diabe14 = b.diabe14 or missing(a.diabe14) or missing(b.diabe14) ) /* & abs(a.pct_a1c_hat-b.pct_a1c_hat)<=(1.5*a.pct_a1c_sd) */ order a.hhidpn,calculated distance; create table no_donora1c&yr as select b.* from miss_donora1c&yr (where=(donor_id = .)) a left join bio.bio_imp20tiles_wide b on a.hhidpn = b.hhidpn ; create table miss_donora1c_nd&yr as select a.hhidpn,&wv as a1c_nm_wave,a.pct_a1c_hat&yr as pct_a1c_hat,a.pct_a1c&yr as pct_a1c_nm,b.hhidpn as donor_id, b.pct_a1c_hat&yr as donorpct_a1c_hat, b.pct_a1c06 as donorpct_a1c06, b.pct_a1c08 as donorpct_a1c08, b.pct_a1c10 as donorpct_a1c10, b.pct_a1c12 as donorpct_a1c12, b.pct_a1c12 as donorpct_a1c14, abs(a.pct_a1c_hat&yr - b.pct_a1c_hat&yr) as distance from no_donora1c&yr (where=((a1c_onewave=1 or a1c_twowaves_sas=1) & pct_a1c&yr ne . and pct_a1c_hat&yr ne . )) a left join bio.bio_imp20tiles_wide (where=((a1c_threewaves=1 or a1c_twowaves_nosas=1) & pct_a1c&yr ne . and pct_a1c_hat&yr ne . )) b on a.pct_a1c&yr = b.pct_a1c&yr /* & abs(a.pct_a1c_hat&yr-b.pct_a1c_hat&yr)<=(1.5*a.pct_a1c_sd&yr) */ order a.hhidpn,calculated distance; data miss_donora1c&yr ; merge miss_donora1c&yr miss_donora1c_nd&yr ; by hhidpn ; run; %mend; %sqlyr(06,8) %sqlyr(08,9) %sqlyr(10,10) %sqlyr(12,11) %sqlyr(14,12) proc sql; create table miss_donora1c as select a.hhidpn,0 as a1c_nm_wave, a.pct_a1c_hat,b.pct_a1c_hat as donorpct_a1c_hat,b.hhidpn as donor_id, b.pct_a1c06 as donorpct_a1c06, b.pct_a1c08 as donorpct_a1c08, b.pct_a1c10 as donorpct_a1c10, b.pct_a1c12 as donorpct_a1c12, b.pct_a1c14 as donorpct_a1c14, abs(a.pct_a1c_hat-b.pct_a1c_hat) as distance from bio.bio_imp20tiles_wide (where=(a1c_nowave=1 and pct_a1c_hat ne . )) a left join bio.bio_imp20tiles_wide (where=((a1c_threewaves=1 or a1c_twowaves_nosas=1) and pct_a1c_hat ne . )) b on (a.diabe06 = b.diabe06 or missing(a.diabe06) or missing(b.diabe06) ) & (a.diabe08 = b.diabe08 or missing(a.diabe08) or missing(b.diabe08) ) & (a.diabe10 = b.diabe10 or missing(a.diabe10) or missing(b.diabe10) ) & (a.diabe12 = b.diabe12 or missing(a.diabe12) or missing(b.diabe12) ) & (a.diabe14 = b.diabe14 or missing(a.diabe14) or missing(b.diabe14) ) /* & abs(a.pct_a1c_hat-b.pct_a1c_hat)<=(1.5*a.pct_a1c_sd) */ order a.hhidpn,calculated distance; proc print data=miss_donora1c06 (obs=200); run; proc print data=miss_donora1c10 (where=(donor_id=.) obs=100); title2 donor id missing ; run; title2 selected cases; proc print data=miss_donora1c (obs=200); run; /* only keep 10 in the donor pool */ data setup checkna1c; set miss_donora1c miss_donora1c06 miss_donora1c08 miss_donora1c10 miss_donora1c12 miss_donora1c14; by a1c_nm_wave hhidpn ; retain n_donor; if first.hhidpn then n_donor=0; n_donor=n_donor+1; if last.hhidpn then do; if n_donor>=10 then n_donor_status=3; else if n_donor>=5 then n_donor_status=2; else if n_donor>0 then n_donor_status=1; else n_donor_status=0; output checkna1c; end; /* if one of the candidate donors then assign random number and output */ if n_donor<=10 then do; ran_num=ranuni(&seed); output setup; end; run; proc print data=checkna1c (obs=200) ; run; proc means data=checkna1c; class n_donor_status; var n_donor; run; /*proc print data=checkn&bio (where=(n_donor<5) obs=20); title2 hhidpn-wave with fewer than 5 donors; run; title2; */ proc sort data=setup; by a1c_nm_wave hhidpn ran_num; data imputeda1c; set setup; by a1c_nm_wave hhidpn ; if first.hhidpn; * imp_pct_a1c=donorpct_a1c08; run; proc sort data=imputeda1c out=bio.imputeda1c; by hhidpn; proc print data=bio.imputeda1c (obs=100) ; run; data bio.bio_imp_finala1c; merge bio.imputeda1c (in=_inimp keep=hhidpn donorpct_a1c: a1c_nm_wave) bio.bio_hrs_recoded_prepimp_v1 (in=_inpct) ; by hhidpn ; impflag2_a1c=_inimp; if missing(pct_a1c) and wave=8 then pct_a1c=donorpct_a1c06; if missing(pct_a1c) and wave=9 then pct_a1c=donorpct_a1c08; if missing(pct_a1c) and wave=10 then pct_a1c=donorpct_a1c10; if missing(pct_a1c) and wave=11 then pct_a1c=donorpct_a1c12; if missing(pct_a1c) and wave=12 then pct_a1c=donorpct_a1c14; if impflag2_a1c=1 and missing(pct_a1c)=1 then impflag2_a1c=9; run; proc contents data=bio.bio_imp_finala1c; run; proc means data=bio.bio_imp_finala1c; class impflag2_a1c; types () impflag2_a1c; var pct_a1c ; run; /*************************************************; ** SYSBP; *************************************************;*/ /* select stddev(pct_a1c_hat) into :a1c_sd from bio.fname; */ %macro sqlyr(yr,wv); proc sql; create table miss_donorsysbp&yr as select a.hhidpn,&wv as sysbp_nm_wave,a.pct_sysbp_hat&yr as pct_sysbp_hat,a.pct_sysbp&yr as pct_sysbp_nm,b.hhidpn as donor_id, b.pct_sysbp_hat&yr as donorpct_sysbp_hat, b.pct_sysbp06 as donorpct_sysbp06, b.pct_sysbp08 as donorpct_sysbp08, b.pct_sysbp10 as donorpct_sysbp10, b.pct_sysbp12 as donorpct_sysbp12, b.pct_sysbp14 as donorpct_sysbp14, abs(a.pct_sysbp_hat&yr - b.pct_sysbp_hat&yr) as distance from bio.bio_imp20tiles_wide (where=((sysbp_onewave=1 or sysbp_twowaves_sas=1) & pct_sysbp&yr ne . and pct_sysbp_hat&yr ne . )) a left join bio.bio_imp20tiles_wide (where=((sysbp_threewaves=1 or sysbp_twowaves_nosas=1) & pct_sysbp&yr ne . and pct_sysbp_hat&yr ne . )) b on a.pct_sysbp&yr = b.pct_sysbp&yr & (a.hibpe06 = b.hibpe06 or missing(a.hibpe06) or missing(b.hibpe06) ) & (a.hibpe08 = b.hibpe08 or missing(a.hibpe08) or missing(b.hibpe08) ) & (a.hibpe10 = b.hibpe10 or missing(a.hibpe10) or missing(b.hibpe10) ) & (a.hibpe12 = b.hibpe12 or missing(a.hibpe12) or missing(b.hibpe12) ) & (a.hibpe14 = b.hibpe14 or missing(a.hibpe14) or missing(b.hibpe14) ) /* & abs(a.pct_sysbp_hat-b.pct_sysbp_hat)<=(1.5*a.pct_sysbp_sd) */ order a.hhidpn,calculated distance; create table no_donorsysbp&yr as select b.* from miss_donorsysbp&yr (where=(donor_id = .)) a left join bio.bio_imp20tiles_wide b on a.hhidpn = b.hhidpn ; create table miss_donorsysbp_nd&yr as select a.hhidpn,&wv as sysbp_nm_wave,a.pct_sysbp_hat&yr as pct_sysbp_hat,a.pct_sysbp&yr as pct_sysbp_nm,b.hhidpn as donor_id, b.pct_sysbp_hat&yr as donorpct_sysbp_hat, b.pct_sysbp06 as donorpct_sysbp06, b.pct_sysbp08 as donorpct_sysbp08, b.pct_sysbp10 as donorpct_sysbp10, b.pct_sysbp12 as donorpct_sysbp12, b.pct_sysbp14 as donorpct_sysbp14, abs(a.pct_sysbp_hat&yr - b.pct_sysbp_hat&yr) as distance from no_donorsysbp&yr (where=((sysbp_onewave=1 or sysbp_twowaves_sas=1) & pct_sysbp&yr ne . and pct_sysbp_hat&yr ne . )) a left join bio.bio_imp20tiles_wide (where=((sysbp_threewaves=1 or sysbp_twowaves_nosas=1) & pct_sysbp&yr ne . and pct_sysbp_hat&yr ne . )) b on a.pct_sysbp&yr = b.pct_sysbp&yr /* & abs(a.pct_sysbp_hat&yr-b.pct_sysbp_hat&yr)<=(1.5*a.pct_sysbp_sd&yr) */ order a.hhidpn,calculated distance; data miss_donorsysbp&yr ; merge miss_donorsysbp&yr miss_donorsysbp_nd&yr ; by hhidpn ; run; %mend; %sqlyr(06,8) %sqlyr(08,9) %sqlyr(10,10) %sqlyr(12,11) %sqlyr(14,12) proc sql; create table miss_donorsysbp as select a.hhidpn,0 as sysbp_nm_wave, a.pct_sysbp_hat,b.pct_sysbp_hat as donorpct_sysbp_hat,b.hhidpn as donor_id, b.pct_sysbp06 as donorpct_sysbp06, b.pct_sysbp08 as donorpct_sysbp08, b.pct_sysbp10 as donorpct_sysbp10, b.pct_sysbp12 as donorpct_sysbp12, b.pct_sysbp14 as donorpct_sysbp14, abs(a.pct_sysbp_hat-b.pct_sysbp_hat) as distance from bio.bio_imp20tiles_wide (where=(sysbp_nowave=1 and pct_sysbp_hat ne . )) a left join bio.bio_imp20tiles_wide (where=((sysbp_threewaves=1 or sysbp_twowaves_nosas=1) and pct_sysbp_hat ne . )) b on (a.hibpe06 = b.hibpe06 or missing(a.hibpe06) or missing(b.hibpe06) ) & (a.hibpe08 = b.hibpe08 or missing(a.hibpe08) or missing(b.hibpe08) ) & (a.hibpe10 = b.hibpe10 or missing(a.hibpe10) or missing(b.hibpe10) ) & (a.hibpe12 = b.hibpe12 or missing(a.hibpe12) or missing(b.hibpe12) ) & (a.hibpe14 = b.hibpe14 or missing(a.hibpe14) or missing(b.hibpe14) ) /* & abs(a.pct_sysbp_hat-b.pct_sysbp_hat)<=(1.5*a.pct_sysbp_sd) */ order a.hhidpn,calculated distance; proc print data=miss_donorsysbp06 (obs=200); run; proc print data=miss_donorsysbp10 (where=(donor_id=.) obs=100); title2 donor id missing ; run; title2 selected cases; proc print data=miss_donorsysbp (obs=200); run; /* only keep 10 in the donor pool */ data setup checknsysbp; set miss_donorsysbp miss_donorsysbp06 miss_donorsysbp08 miss_donorsysbp10 miss_donorsysbp12 miss_donorsysbp14; by sysbp_nm_wave hhidpn ; retain n_donor; if first.hhidpn then n_donor=0; n_donor=n_donor+1; if last.hhidpn then do; if n_donor>=10 then n_donor_status=3; else if n_donor>=5 then n_donor_status=2; else if n_donor>0 then n_donor_status=1; else n_donor_status=0; output checknsysbp; end; /* if one of the candidate donors then assign random number and output */ if n_donor<=10 then do; ran_num=ranuni(&seed); output setup; end; run; proc print data=checknsysbp (obs=200) ; run; proc means data=checknsysbp; class n_donor_status; var n_donor; run; /*proc print data=checkn&bio (where=(n_donor<5) obs=20); title2 hhidpn-wave with fewer than 5 donors; run; title2; */ proc sort data=setup; by sysbp_nm_wave hhidpn ran_num; data imputedsysbp; set setup; by sysbp_nm_wave hhidpn ; if first.hhidpn; * imp_pct_sysbp=donorpct_sysbp08; run; proc sort data=imputedsysbp out=bio.imputedsysbp; by hhidpn; proc print data=bio.imputedsysbp (obs=100) ; run; data bio.bio_imp_finalsysbp; merge bio.imputedsysbp (in=_inimp keep=hhidpn donorpct_sysbp: sysbp_nm_wave) bio.bio_hrs_recoded_prepimp_v1 (in=_inpct) ; by hhidpn ; impflag2_sysbp=_inimp; if missing(pct_sysbp) and wave=8 then pct_sysbp=donorpct_sysbp06; if missing(pct_sysbp) and wave=9 then pct_sysbp=donorpct_sysbp08; if missing(pct_sysbp) and wave=10 then pct_sysbp=donorpct_sysbp10; if missing(pct_sysbp) and wave=11 then pct_sysbp=donorpct_sysbp12; if missing(pct_sysbp) and wave=12 then pct_sysbp=donorpct_sysbp14; if impflag2_sysbp=1 and missing(pct_sysbp)=1 then impflag2_sysbp=9; run; proc contents data=bio.bio_imp_finalsysbp; run; proc means data=bio.bio_imp_finalsysbp; class impflag2_sysbp; types () impflag2_sysbp; var pct_sysbp ; run; /*************************************************; ** crp; *************************************************;*/ %macro sqlyr(yr,wv); proc sql; create table miss_donorcrp&yr as select a.hhidpn,&wv as crp_nm_wave,a.pct_crp_hat&yr as pct_crp_hat,a.pct_crp&yr as pct_crp_nm,b.hhidpn as donor_id, b.pct_crp_hat&yr as donorpct_crp_hat, b.pct_crp06 as donorpct_crp06, b.pct_crp08 as donorpct_crp08, b.pct_crp10 as donorpct_crp10, b.pct_crp12 as donorpct_crp12, b.pct_crp14 as donorpct_crp14, abs(a.pct_crp_hat&yr - b.pct_crp_hat&yr) as distance from bio.bio_imp20tiles_wide (where=((crp_onewave=1 or crp_twowaves_sas=1) & pct_crp&yr ne . and pct_crp_hat&yr ne . )) a left join bio.bio_imp20tiles_wide (where=((crp_threewaves=1 or crp_twowaves_nosas=1) & pct_crp&yr ne . and pct_crp_hat&yr ne . )) b on a.pct_crp&yr = b.pct_crp&yr & (a.cancre06 = b.cancre06 or missing(a.cancre06) or missing(b.cancre06) ) & (a.cancre08 = b.cancre08 or missing(a.cancre08) or missing(b.cancre08) ) & (a.cancre10 = b.cancre10 or missing(a.cancre10) or missing(b.cancre10) ) & (a.cancre12 = b.cancre12 or missing(a.cancre12) or missing(b.cancre12) ) /* & abs(a.pct_crp_hat-b.pct_crp_hat)<=(1.5*a.pct_crp_sd) */ order a.hhidpn,calculated distance; create table no_donorcrp&yr as select b.* from miss_donorcrp&yr (where=(donor_id = .)) a left join bio.bio_imp20tiles_wide b on a.hhidpn = b.hhidpn ; create table miss_donorcrp_nd&yr as select a.hhidpn,&wv as crp_nm_wave,a.pct_crp_hat&yr as pct_crp_hat,a.pct_crp&yr as pct_crp_nm,b.hhidpn as donor_id, b.pct_crp_hat&yr as donorpct_crp_hat, b.pct_crp06 as donorpct_crp06, b.pct_crp08 as donorpct_crp08, b.pct_crp10 as donorpct_crp10, b.pct_crp12 as donorpct_crp12, b.pct_crp14 as donorpct_crp14, abs(a.pct_crp_hat&yr - b.pct_crp_hat&yr) as distance from no_donorcrp&yr (where=((crp_onewave=1 or crp_twowaves_sas=1) & pct_crp&yr ne . and pct_crp_hat&yr ne . )) a left join bio.bio_imp20tiles_wide (where=((crp_threewaves=1 or crp_twowaves_nosas=1) & pct_crp&yr ne . and pct_crp_hat&yr ne . )) b on a.pct_crp&yr = b.pct_crp&yr /* & abs(a.pct_crp_hat&yr-b.pct_crp_hat&yr)<=(1.5*a.pct_crp_sd&yr) */ order a.hhidpn,calculated distance; data miss_donorcrp&yr ; merge miss_donorcrp&yr miss_donorcrp_nd&yr ; by hhidpn ; run; %mend; %sqlyr(06,8) %sqlyr(08,9) %sqlyr(10,10) %sqlyr(12,11) %sqlyr(14,12) proc sql; create table miss_donorcrp as select a.hhidpn,0 as crp_nm_wave, a.pct_crp_hat,b.pct_crp_hat as donorpct_crp_hat,b.hhidpn as donor_id, b.pct_crp06 as donorpct_crp06, b.pct_crp08 as donorpct_crp08, b.pct_crp10 as donorpct_crp10, b.pct_crp12 as donorpct_crp12, b.pct_crp14 as donorpct_crp14, abs(a.pct_crp_hat-b.pct_crp_hat) as distance from bio.bio_imp20tiles_wide (where=(crp_nowave=1 and pct_crp_hat ne . )) a left join bio.bio_imp20tiles_wide (where=((crp_threewaves=1 or crp_twowaves_nosas=1) and pct_crp_hat ne . )) b on (a.cancre06 = b.cancre06 or missing(a.cancre06) or missing(b.cancre06) ) & (a.cancre08 = b.cancre08 or missing(a.cancre08) or missing(b.cancre08) ) & (a.cancre10 = b.cancre10 or missing(a.cancre10) or missing(b.cancre10) ) & (a.cancre12 = b.cancre12 or missing(a.cancre12) or missing(b.cancre12) ) & (a.cancre14 = b.cancre14 or missing(a.cancre14) or missing(b.cancre14) ) /* & abs(a.pct_crp_hat-b.pct_crp_hat)<=(1.5*a.pct_crp_sd) */ order a.hhidpn,calculated distance; proc print data=miss_donorcrp06 (obs=200); run; proc print data=miss_donorcrp10 (where=(donor_id=.) obs=100); title2 donor id missing ; run; title2 selected cases; proc print data=miss_donorcrp (obs=200); run; /* only keep 10 in the donor pool */ data setup checkncrp; set miss_donorcrp miss_donorcrp06 miss_donorcrp08 miss_donorcrp10 miss_donorcrp12 miss_donorcrp14; by crp_nm_wave hhidpn ; retain n_donor; if first.hhidpn then n_donor=0; n_donor=n_donor+1; if last.hhidpn then do; if n_donor>=10 then n_donor_status=3; else if n_donor>=5 then n_donor_status=2; else if n_donor>0 then n_donor_status=1; else n_donor_status=0; output checkncrp; end; /* if one of the candidate donors then assign random number and output */ if n_donor<=10 then do; ran_num=ranuni(&seed); output setup; end; run; proc print data=checkncrp (obs=200) ; run; proc means data=checkncrp; class n_donor_status; var n_donor; run; /*proc print data=checkn&bio (where=(n_donor<5) obs=20); title2 hhidpn-wave with fewer than 5 donors; run; title2; */ proc sort data=setup; by crp_nm_wave hhidpn ran_num; data imputedcrp; set setup; by crp_nm_wave hhidpn ; if first.hhidpn; * imp_pct_crp=donorpct_crp08; run; proc sort data=imputedcrp out=bio.imputedcrp; by hhidpn; proc print data=bio.imputedcrp (obs=100) ; run; data bio.bio_imp_finalcrp; merge bio.imputedcrp (in=_inimp keep=hhidpn donorpct_crp: crp_nm_wave) bio.bio_hrs_recoded_prepimp_v1 (in=_inpct) ; by hhidpn ; impflag2_crp=_inimp; if missing(pct_crp) and wave=8 then pct_crp=donorpct_crp06; if missing(pct_crp) and wave=9 then pct_crp=donorpct_crp08; if missing(pct_crp) and wave=10 then pct_crp=donorpct_crp10; if missing(pct_crp) and wave=11 then pct_crp=donorpct_crp12; if missing(pct_crp) and wave=12 then pct_crp=donorpct_crp14; if impflag2_crp=1 and missing(pct_crp)=1 then impflag2_crp=9; run; proc contents data=bio.bio_imp_finalcrp; run; proc means data=bio.bio_imp_finalcrp; class impflag2_crp; types () impflag2_crp; var pct_crp ; run; data bio.bio_imp_all ; merge bio.bio_imp_finala1c bio.bio_imp_finalhdl (keep=hhidpn wave donorpct_hdl06 donorpct_hdl08 donorpct_hdl10 donorpct_hdl12 donorpct_hdl14 pct_hdl impflag2_hdl pct_hdl_hat) bio.bio_imp_finaltchol (keep=hhidpn wave donorpct_tchol06 donorpct_tchol08 donorpct_tchol10 donorpct_tchol12 donorpct_tchol14 pct_tchol impflag2_tchol pct_tchol_hat) bio.bio_imp_finalsysbp (keep=hhidpn wave donorpct_sysbp06 donorpct_sysbp08 donorpct_sysbp10 donorpct_sysbp12 donorpct_sysbp14 pct_sysbp impflag2_sysbp pct_sysbp_hat) bio.bio_imp_finalcrp (keep=hhidpn wave donorpct_crp06 donorpct_crp08 donorpct_crp10 donorpct_crp12 donorpct_crp14 pct_crp impflag2_crp pct_crp_hat) ; by hhidpn wave ; run;