Hi, I am working with two datasets (x and y) and I would like to exclude all observations that are in dataset Y from dataset X.
For example, my datasets look like this
Dataset X Dataset Y
ID Value IDNUM
1 25 2
2 30
3 50
This is pretty straightforward when using PROC SQL.
proc sql;
create table selected as
select *
from X
where ID not in (select IDNUM from Y);
quit;
@kmardinian wrote:
Hi, I am working with two datasets (x and y) and I would like to exclude all observations that are in dataset Y from dataset X.
For example, my datasets look like this
Dataset X Dataset Y
ID Value IDNUM
1 25 2
2 30
3 50
I would like to find a way where I can tell SAS that I want observations for ID 2 to be deleted from dataset X, but the ID variables are also named differently. Any advice on where to start and how to go about this would be very helpful! Thank you!
This is pretty straightforward when using PROC SQL.
proc sql;
create table selected as
select *
from X
where ID not in (select IDNUM from Y);
quit;
@kmardinian wrote:
Hi, I am working with two datasets (x and y) and I would like to exclude all observations that are in dataset Y from dataset X.
For example, my datasets look like this
Dataset X Dataset Y
ID Value IDNUM
1 25 2
2 30
3 50
I would like to find a way where I can tell SAS that I want observations for ID 2 to be deleted from dataset X, but the ID variables are also named differently. Any advice on where to start and how to go about this would be very helpful! Thank you!
Thank you Reeza, that is super straightforward. Thank you for your help!
Assuming both datasets are sorted correctly:
data want;
merge
x (in=x)
y (in=y rename=(idnum=id))
;
by id;
if x and not y;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.