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;
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!
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.
Ready to level-up your skills? Choose your own adventure.