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

Hi, 

I've records in A, B , C datasets and all have a common column named Subject_ID(multiple recors per subject_id) . I want to filter the Subject_IDs which are in A but not in B&C(together). 

 

below code doesn't give any syntax errors but not giving correct results also, shall require help.

 

proc sql;
create table filter as select distinct subject_ID from A where subject_ID not in
(select distinct subject_ID from B where subject_ID not in (select distinct subject_ID from C));
quit;

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

See if you can use this as a template. You can also do this with inner joins.

 

data a;
input subject_ID;
datalines;
1
2
3
4
5
;

data b;
input subject_ID;
datalines;
1
3
5
;

data c;
input subject_ID;
datalines;
1
2
3
;

proc sql;
   create table want as
   select * from a where subject_ID not in (select subject_ID from b)
                     and subject_ID not in (select subject_ID from c);
quit;

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

See if you can use this as a template. You can also do this with inner joins.

 

data a;
input subject_ID;
datalines;
1
2
3
4
5
;

data b;
input subject_ID;
datalines;
1
3
5
;

data c;
input subject_ID;
datalines;
1
2
3
;

proc sql;
   create table want as
   select * from a where subject_ID not in (select subject_ID from b)
                     and subject_ID not in (select subject_ID from c);
quit;
Ksharp
Super User
data a;
input subject_ID;
datalines;
1
2
3
4
5
;

data b;
input subject_ID;
datalines;
1
3
5
;

data c;
input subject_ID;
datalines;
1
2
3
;

proc sql;
   create table want as
   select subject_ID from a 
   except
   select subject_ID from b
   except
   select subject_ID from c 
;
quit;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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