BookmarkSubscribeRSS Feed
wil1212
Calcite | Level 5

I would like to merge three datasets A, B, and C to find all the obs in A that do not match B and C. B and C are both subsets of A. Obs in B and C do not match each other.

 

I have tried the code below and many other logic test, but I cannot seem to get the right output. Any help would be appreciated.

 

data want;

merge A(in= inA) B(in=inB) C(in=inC);

by id date;

if not inA or (not inB and not inC) then

output want;

run;

1 REPLY 1
bnawrocki
Quartz | Level 8

So you want to keep all records in A that don't find matches in either B or C?

 

I would suggest this code:

data want;
   merge a(in=inA) b(in=inB) c(in=inC);
   by id date;
   if inA and not inB and not inC;
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 1 reply
  • 714 views
  • 3 likes
  • 2 in conversation