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

Hi ,

 

I merged two datasets using the code below. How do I export or output the IDs and observations in "LOS2" dataset that were not merged into "four" dataset?

 

data five;
merge four (in=a) LOS2 (keep = ID Admission_date Discharge_date LOS Discharge);
by ID;
if a = 1;
run;

 

Thank you in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star
data five;
merge four (in=a) 
           LOS2 (in = b keep = ID Admission_date Discharge_date LOS Discharge);
by ID;
if b and not a;
run;

View solution in original post

2 REPLIES 2
ballardw
Super User
data five other;
   merge four (in=a) 
              LOS2 (keep = ID Admission_date Discharge_date LOS Discharge);
    by ID;
    if a = 1 then output five;
    else output other;
run;

You need to 1) specify another data set on the Data statement, 2) conditionally indicate which specific data set using OUTPUT statements which data set each group of records gets written to.

SASKiwi
PROC Star
data five;
merge four (in=a) 
           LOS2 (in = b keep = ID Admission_date Discharge_date LOS Discharge);
by ID;
if b and not a;
run;

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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