BookmarkSubscribeRSS Feed
nwang5
Obsidian | Level 7

Hi All,

 

I hope this message finds you well. I am trying to the characteristics of the participants included and exclude. Here are my inclusion criteria. How could I get the dataset that I excluded? Thanks!

 

data elsa02;
set elsa01;

if age1<50 or age2<50 then delete;

if sight_persist=. then delete;
if hear_persist=. then delete;

if (cesd1>=0 or cesd2>=0);
if missing(cesd1) then cesd1=cesd2;
if missing(cesd2) then cesd2=cesd1;

if cesd3=. and cesd4=. and cesd5=. and cesd6=. and cesd7=. and cesd8=. and cesd9=. then delete;
if n(of cesd3-cesd9)<2 then delete;

if (cesd1>=3 or cesd2>=3) then delete;
run;

3 REPLIES 3
LinusH
Tourmaline | Level 20

Haven't tried this, but for each DELETE, add en explicit output:

then do;
   output excluded;
   delete;
end;

Another option could be to join elsa01 with elsa02 using a NOT IN( ) condition.

Data never sleeps
s_lassen
Meteorite | Level 14

I think your program can be rewritten as (not tested):

data elsa02 excluded;
set elsa01;

if age1<50 or age2<50 or 
   sight_persist=. or
   hear_persist=. or
   not (cesd1>=0 or cesd2>=0) or
   n(of cesd3-cesd9)<2 or
   (cesd1>=3 or cesd2>=3) then 
  output excluded;
else do;
  if missing(cesd1) then cesd1=cesd2;
  if missing(cesd2) then cesd2=cesd1;
  output elsa02;
  end;
run;

Explanation: I changed the subsetting IF to a condition preceded by NOT: "not (cesd1>=0 or cesd2>=0)"

The line 

if cesd3=. and cesd4=. and cesd5=. and cesd6=. and cesd7=. and cesd8=. and cesd9=. then delete;

is not necessary, as it is covered by the "n(of cesd3-cesd9)<2" condition.

 

Kurt_Bremser
Super User

Combine your conditions into a single IF:

data
  elsa02
  excluded
;
set elsa01;
if
  (cesd1 < 0 and cesd2 < 0)
  or age1 < 50 or age2 < 50
  or sight_persist = . or hear_persist = .
  or n(of cesd3-cesd9) < 2
  or cesd1 >= 3 or cesd2 >= 3
then output exclude;
else do;
  if missing(cesd1) then cesd1 = cesd2;
  if missing(cesd2) then cesd2 = cesd1;
  output elsa02;
end;
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 327 views
  • 3 likes
  • 4 in conversation