proc sort data=dataset1;
by ID;
run;
proc sort data=dataset2;
by ID;
run;
data dataset2;
merge dataset2 (in=a)
dataset1 (in=b);
by ID;
if a;
run;
Is this overwriting the existing dataset2, and applying the merge operation ?
It is doing left join on data
According to your code it will overwrite the dataset2 and keep the variables and of data in variable ID if existing in both datasets or if not existing in dataset1 and keep osb existing in dataset2
Yes
yeah..its going to overwrite the data with maching BY variable's and lefts the remaining in dataset 2.
in simple term LEFT JOIN
Vish33 and manojinpec,
If the 'LEFT JOIN' you mentioned is the SQL LEFT JOIN, then you were wrong. SQL LEFT JOIN will keep the value of first table instead.
Regards,
Haikuo
Haikuo,
Thanks for info...that was a blind mistake of mine..:)
Yes, the source dataset2 (the one in the merge statement) will be replaced by the same named target data set (the one in the data statement) in case the data step finishes without errors.
A SAS merge is not the same like a SQL join because a SAS merge statement behaves differently to a SQL join in case of many-to-many relationships.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.