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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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