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;

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