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

Hi, I'm still new at using SAS and I wanted to merge two large datasets, using two common variables (MRN and UEN). I'm using SAS studio.

First dataset (on a much smaller scale):

MRN UEN Drug

1234   1       x

1234   2       x

4567   1       x

7891   1       x

 

Second dataset (on a much smaller scale):

MRN UEN Doctor

1234   1         y

1234   2         y

4567   1         y

7891   1         y

 

I need the final table to look like this

MRN UEN Drug Doctor

1234   1       x        y

1234   2       x        y

4567   1       x        y

7891   1       x        y

 

Not sure how to go about it. Any help would be appreciated! Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20
data one;
input MRN UEN Drug $;
datalines;
1234   1       x
1234   2       x
4567   1       x
7891   1       x
;

data two;
input MRN UEN Doctor $;
datalines;
1234   1         y
1234   2         y
4567   1         y
7891   1         y
;

proc sort data=one;
    by MRN UEN;
run;

proc sort data=two;
    by MRN UEN;
run;

data want;
    merge one two;
    by MRN UEN;
run;

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20
data one;
input MRN UEN Drug $;
datalines;
1234   1       x
1234   2       x
4567   1       x
7891   1       x
;

data two;
input MRN UEN Doctor $;
datalines;
1234   1         y
1234   2         y
4567   1         y
7891   1         y
;

proc sort data=one;
    by MRN UEN;
run;

proc sort data=two;
    by MRN UEN;
run;

data want;
    merge one two;
    by MRN UEN;
run;
Martina_Salib
Calcite | Level 5
?Thank you! That was really helpful!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 479 views
  • 1 like
  • 2 in conversation