BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kmardinian
Quartz | Level 8

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!
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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!

 

View solution in original post

3 REPLIES 3
Reeza
Super User

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!

 

kmardinian
Quartz | Level 8

Thank you Reeza, that is super straightforward. Thank you for your help!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 3467 views
  • 2 likes
  • 3 in conversation