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!

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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