BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
msyteriouspages
Calcite | Level 5
I have a huge dataset that I want to subset based on values that already exist in another dataset. For example:

Dataset A

ID Dollars
1 100
2 135

Dataset B

Key Age App Funds
1 23 1 1000
1 23 2 1500
2 22 1 6700
2 22 2 2000
3 26 1 3100
3 26 2 2300

I wanted to create a list (maybe a macro list would be suitable?) based on the ID values from Dataset A, e.g.
IDlist = 1,2

Then, I would like to subset Dataset B based on ID’s that exist in our previously created IDlist. And I would use this in a proc sql (or data step) like:

proc sql:
create table want as
Select *
From B
Where key in IDlist;
quit;

The ideal subsetted dataset B should look like:

Data want:

Key Age App Funds
1 23 1 1000
1 23 2 1500
2 22 1 6700
2 22 2 2000

If anyone has dealt with something like this before, I’d appreciate any input. Thank you!
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
proc sql:
create table want as
Select *
From B
Where key in (select id from A) ;
quit;

View solution in original post

4 REPLIES 4
tarheel13
Rhodochrosite | Level 12
People are going to get mad at you if you don’t paste the datasets as datalines.
msyteriouspages
Calcite | Level 5
Hi, sorry, I’m new to SAS communities. Any tips on how I could paste them as datalines?
tarheel13
Rhodochrosite | Level 12
Data A;
input ID dollars;
datalines;
1 100
2 135
;
run;

Like that. Also, if you are posting code, please use the insert SAS code button.

Ksharp
Super User
proc sql:
create table want as
Select *
From B
Where key in (select id from A) ;
quit;

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
  • 4 replies
  • 2532 views
  • 2 likes
  • 3 in conversation