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

Below is a homework question with some data. I have done pieces of this that work well (rename, merge, catx) but when I try to run multiple pieces of it together, it never comes out looking quite right. I have never merged two data sets together before, so I'm hoping someone can show me how it's done on this problem.

 

The temporary SAS data sets ‘StJohns’ and ‘CM’ below show data sets containing the same information.  However, this information was collected differently at each site (different variable names, variable values, etc.).

 

SAS Data Set ‘StJohns’

 

Site

PatientID

FirstNm

LastNm

Sex

1

St Johns

203

Daniel

Taylor

M

2

St Johns

206

Helen

Davis

F

3

St Johns

208

Betty

Smith

f

 

SAS Data Set ‘CM’

 

Institution

SubjID

Name

Gender

1

City Medics

102

Wilson, Steven

Male

2

City Medics

105

Moore, Chris

male

3

City Medics

109

Jackson, Sharon

Female

 

Write SAS code which will combine the 2 data sets above into the single data set named ‘AllSites’ with attributes and values exactly as shown below.

SAS Data Set ‘AllSites’

 

Institution

SubjID

Name

SexCd

1

City Medics

102

Wilson, Steven

M

2

City Medics

105

Moore, Chris

M

3

City Medics

109

Jackson, Sharon

F

4

St Johns

203

Taylor, Daniel

M

5

St Johns

206

Davis, Helen

F

6

St Johns

208

Smith, Betty

F

 

 

Here are the datelines: 

DATA StJohns;
INFILE DATALINES;
INPUT Site $8. 
    PatientID 
    FirstNm $
    LastNm $
    Sex $;
DATALINES;
St Johns 203 Daniel Taylor M
St Johns 206 Helen Davis F
St Johns 208 Betty Smith f
;

DATA CM;
INFILE DATALINES DSD DLM=' ';
INPUT Institution :$11. 
    SubjID 
    Name :$15.
    Gender :$6.;
DATALINES;
'City Medics' 102 'Wilson, Steven' Male
'City Medics' 105 'Moore, Chris' male
'City Medics' 109 'Jackson, Sharon' Female
;
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

That is not a MERGE.  A MERGE involves matching observations based on some common key variable.

Your data has no common variables that could be used to match observations.

 

Looking at the output desired it looks like you just want to concatenating the observations from both datasets.

 

Since the variable names are different you will need to first rename some of them to be the same.

 

Once you have two datasets that both have the same set of variables just use a SET statement that lists both datasets to "stack" them.

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

That is not a MERGE.  A MERGE involves matching observations based on some common key variable.

Your data has no common variables that could be used to match observations.

 

Looking at the output desired it looks like you just want to concatenating the observations from both datasets.

 

Since the variable names are different you will need to first rename some of them to be the same.

 

Once you have two datasets that both have the same set of variables just use a SET statement that lists both datasets to "stack" them.

Desi2003
Calcite | Level 5

Thanks, this worked perfectly. The last piece I am struggling with is the SexCd. How do I make the values uniform?

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 912 views
  • 0 likes
  • 2 in conversation