DATA Step, Macro, Functions and more

Merge Operation

Reply
N/A
Posts: 1

Merge Operation

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 ?

Frequent Contributor
Posts: 138

Re: Merge Operation

It is doing left join on data

Frequent Contributor
Posts: 140

Merge Operation

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

Super User
Posts: 5,256

Re: Merge Operation

Yes

Data never sleeps
Frequent Contributor
Posts: 117

Re: Merge Operation

yeah..its going to overwrite the data with maching BY variable's and lefts the remaining in dataset 2.

in simple term LEFT JOIN

Respected Advisor
Posts: 3,124

Re: Merge Operation

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

Frequent Contributor
Posts: 117

Re: Merge Operation

Haikuo,

Thanks for info...that was a blind mistake of mine..Smiley Happy

Respected Advisor
Posts: 3,889

Re: Merge Operation

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.

Ask a Question
Discussion stats
  • 7 replies
  • 255 views
  • 0 likes
  • 7 in conversation