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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1187 views
  • 2 likes
  • 4 in conversation