BookmarkSubscribeRSS Feed
suzannep
Calcite | Level 5

Hi, 

 

I have two data sets. Data set A has 1,000 observations and data set B (subset of data set A) with 800 observations. I want to make a data set C that ONLY has the other 200 observations from data set A. 

 

I'm sure there is some easy code for this but I just don't know what it is. Please help!

 

Thanks! 

4 REPLIES 4
Zad
Calcite | Level 5 Zad
Calcite | Level 5

proc sort data=a;by common_surveyid;

proc sort data=b;by common_surveyid;run;

 

data a_b;merge a(in=a) b(in=b);

by common_surveyid;

if a and not b;

run;

Kurt_Bremser
Super User

While your code will provide the intended results, it looks horrible.

Compare this;

proc sort data=a;
by common_surveyid;
run;

proc sort data=b;
by common_surveyid;
run;
 
data a_b;
merge
  a (in=a)
  b (in=b)
;
by common_surveyid;
if a and not b;
run;

and tell me, which one is easier to read and understand for another coder?

ballardw
Super User

Or possibly

 

Proc Sql;
   create table want as
   select * from tableA
   except
   select * from tableb
  ;
quit;