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

Hello,

 

Using SAS 9.4

 

I have 2 data sets that have roughly the same data. Some of the variables overlap (i.e. name, dob, etc.) and some of the variables are exclusive to 1 data set or the other. I need to keep everything from both data sets. 

 

Typically I would use something like: 

data merged;
dataset1 (in=a) dataset2 (in=b);
run;

 

For these 2 data sets both have an ID that is for each patient, however some of the IDs duplicate between the 2 data sets. I need to keep both of the duplicate IDs without losing any of their information. 

 

Is their a way to essentially stack the 2 data sets together without losing the information in the duplicate IDs? Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Without samples of what you have and what you want, my dumb brain isn't able to guess your exact requirement

 

Are you after this by any chance?

 

data merged;
set dataset1 dataset2 ;
run;

 

EDIT :  @ballardw   Sorry sir, i didn't see your message. My apologies for the duplication of the same approaches. 

View solution in original post

3 REPLIES 3
ballardw
Super User

Can you provide two small example data sets similar to your start and what you would want for the output?

 

Since you did not show either a SET, MERGE, UPDATE or MODIFY statement in your example code it isn't possible to tell exactly what you may have done previously.

 

A SET statement would stack the data sets with no loss

data merged;
   set dataset1 (in=a) dataset2 (in=b);
run;

This assumes all of your variables in common between the two sets have the same type (numeric or character) and length. Different lengths will generate messages and possibly truncated data. Different types will not allow the combination to proceed as that would be an error.

novinosrin
Tourmaline | Level 20

Without samples of what you have and what you want, my dumb brain isn't able to guess your exact requirement

 

Are you after this by any chance?

 

data merged;
set dataset1 dataset2 ;
run;

 

EDIT :  @ballardw   Sorry sir, i didn't see your message. My apologies for the duplication of the same approaches. 

ballardw
Super User

@novinosrin wrote:

 

 

EDIT :  @ballardw   Sorry sir, i didn't see your message. My apologies for the duplication of the same approaches. 


No worries. Sometimes different phrasing makes more sense to one person than another. Better to get at least one answer the OP can understand than none.

 

We also know that responses can be close in time because one response wasn't posted at the time you read a question but appears at about the same time when posting responses.

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