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!
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;
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?
You can also do it in SQL:
proc sql;
create table want as
select a.*
from a
where key not in (
select b.key from b
);
quit;
Or possibly
Proc Sql; create table want as select * from tableA except select * from tableb ; quit;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.