BookmarkSubscribeRSS Feed
TMSmith
Calcite | Level 5

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;
3 REPLIES 3
kiranv_
Rhodochrosite | Level 12

 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;

 

 

TMSmith
Calcite | Level 5

Oh, wow. That was such a silly mistake of mine. Thank you!

TMSmith
Calcite | Level 5

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 796 views
  • 0 likes
  • 2 in conversation