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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 391 views
  • 0 likes
  • 2 in conversation