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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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