BookmarkSubscribeRSS Feed
xoxozav_1
Calcite | Level 5

I am trying to merge 2 datasets using a by for the variables, but I am not sure if the method that I am using is the best method to perform One-to-many merge. I only want unique observations in the final dataset.

 

For example, I have 2 data sets, one called mother and other called children. So, one mother may have more than one child.

I started using :

PROC SORT DATA=mother nodupkey out=mother1;
BY v001 v002 ;
RUN;
proc sort data=children nodupkey out=children2;
by v001 v002 ;
run;
 Then I used this method :


data women1children3;
merge mother1 (in=ina) children2 (in=inb);
by v001 v002 v003;
if ina=inb;
run;

 

Is this method correct  for merging one to many, or should I use this one instead: (Defining the file with duplicates as a master)

data want ;
   merge master (in=in1) other ;
   by id;
   if in1 then output;
   in1=0;
run;

 

Thanks for the help!

 
1 REPLY 1

sas-innovate-white.png

🚨 Early Bird Rate Extended!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Lock in the best rate now before the price increases on April 1.

Register now!

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
  • 378 views
  • 0 likes
  • 2 in conversation