BookmarkSubscribeRSS Feed
Ranjeeta
Pyrite | Level 9

MERGE statement has more than one data set with repeats of BY values.

 


218 data MGH_PCI;
219 merge MGH(IN=MGH) PCI(IN=PCI);
220 by HealthCardNumber;
221 if MGH and PCI;
222 run;

 

NOTE: There were 21423 observations read from the data set WORK.MGH.
NOTE: There were 117715 observations read from the data set WORK.PCI.
NOTE: The data set WORK.MGH_PCI has 7265 observations and 240 variables.
NOTE: DATA statement used (Total process time):
real time 0.21 seconds
cpu time 0.15 seconds

 

 

Hello, 

I understnad that the PCI data set has repeat entries for the by variable HealthCardNumber; and therefore I get the above message

But i want to understand which records are used to merge in the case of a repeat entry i.e which records are put into the merged table. Would sas put the first time it encountered a matching HealthCardNumber into the table 

 

 

 

1 REPLY 1
PaigeMiller
Diamond | Level 26

For example, if you have one data set with one record for ID 2039 and the second data set has two records for ID 2039, then the resulting data set after the merge will have two records for ID 2039. The values of variables in the first data set will appear on both merged records, and the values of the variables in the second data set will appear on one merged record. Example:

 

data one;
    id=2039;
	date='01OCT18'd;
	format date date7.;
run;

data two;
    id=2039;
	location='ABC';
	output;
	location='XYZ';
	output;
run;

data merged;
	merge one two;
	by id;
run;
--
Paige Miller

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 565 views
  • 2 likes
  • 2 in conversation