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

Hello,

I need assistance merging two different data sets together. The two datasets look like this:

 

HAVE1

Week_Start   Hospital   Samples    Average

07/05/2020.   Name1.   2.               2

07/05/2020.   Name2.   3               3

07/05/2020.   Name3.   1.              1

07/12/2020.   Name1.   2.               2

07/12/2020.   Name2.   3               3

07/12/2020.   Name3.   1.              1

 

Have2

Week_Start    Hospital.   Cases

07/05/2020.    Name1.     10

07/12/2020.   Name1.      25

 

What I want is to merge the datasets to add the cases column specifically for Hospital Name1. For example, what I WANT;

Week_Start   Hospital   Samples    Average.  Cases

07/05/2020.   Name1.   2.               2.              10

07/05/2020.   Name2.   3               3.                --

07/05/2020.   Name3.   1.              1.                --

07/12/2020.   Name1.   2.               2.             25

07/12/2020.   Name2.   3               3.             --

07/12/2020.   Name3.   1.              1.             --

 

 

Thank you so much for any help you can provide!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Looks like a basic data step merge: Sort the two data sets by the variables you want to match on and use merge with a by statement:

Proc sort data=have1;
   by week_start hospital;
run;

proc sort data=have2;
   by week_start hospital;
run;

data want;
   merge have1 have2;
   by week_start hospital;
run;

This assumes that you do not have multiples of the same values of week_start and hospital in both data sets.

View solution in original post

1 REPLY 1
ballardw
Super User

Looks like a basic data step merge: Sort the two data sets by the variables you want to match on and use merge with a by statement:

Proc sort data=have1;
   by week_start hospital;
run;

proc sort data=have2;
   by week_start hospital;
run;

data want;
   merge have1 have2;
   by week_start hospital;
run;

This assumes that you do not have multiples of the same values of week_start and hospital in both data sets.