Hi all,
I'm having some issues subsetting my dataset. My goal is to create two new datasets (mn2 and mn3) from an original dataset. I want mn2 to contain observations that have no missing values in any of these variables:
hair_mn_ppm
ied_eds_err
ied_preed_err
ied_total_err
wm_comprverbal_w
wm_apprendvisaud_w
wm_relespatial_w
wm_formconcept_w
wm_pareovis_w
wm_inversenum_w
ci_woodcock
and I would like mn3 to contain all that were excluded from mn2. I need to retain both sets of these data because I will need to later report how they differ from one another. Would it be easier just to code new variables all within the original dataset? Am I making my life too hard?
This is the code I've used so far:
data mn2 mn3;
set mn1;
if hair_mn_ppm=. AND ied_eds_err = .
AND ied_preed_err =.
AND ied_total_err =.
AND wm_comprverbal_w =.
AND wm_apprendvisaud_w =.
AND wm_relespatial_w =.
AND wm_formconcept_w =.
AND wm_pareovis_w =.
AND wm_inversenum_w =.
AND ci_woodcock =. THEN OUTPUT mn2;
ELSE OUTPUT mn3;
run;
you need to use "or" instead of "and" an example below. And looks for all or looks for any condition
data abc;
input xyz yxs zzz uuu;
datalines;
1 2 3 7
2 3 4 6
. . . 7
. 8 2 4
6 7 . 6
. 9 . 7
;
data abcd abcde;
set abc;
if (xyz = .) or (yxs = .) or (zzz = .) then output abcde;
else output abcd;
run;
Oh, wow. That was such a silly mistake of mine. Thank you!
Got it. For the sake of those (like myself) who may struggle in the future:
/*getting n with exclusions*/
/*hair*/
data mn2;
set mn1;
if nmiss (hair_mn_ppm, ied_eds_err, ied_preed_err, ied_total_err,wm_comprverbal_w,
wm_apprendvisaud_w, wm_relespacial_w, wm_formconcept_w, wm_pareovis_w, wm_inversnum_w,
ci_woodcock) =0; run;
proc print noobs; run;
/*water*/
data mn3;
set mn1;
if nmiss (water_mn_ppm, ied_eds_err, ied_preed_err, ied_total_err,wm_comprverbal_w,
wm_apprendvisaud_w, wm_relespacial_w, wm_formconcept_w, wm_pareovis_w, wm_inversnum_w,
ci_woodcock) =0; run;
proc print noobs; run;
Best source of help: https://blogs.sas.com/content/iml/2015/02/23/complete-cases.html
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.