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;

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
  • 815 views
  • 0 likes
  • 3 in conversation