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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.