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!
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;
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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.