BookmarkSubscribeRSS Feed
Kishore_01
Calcite | Level 5

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 ?

7 REPLIES 7
manojinpec
Obsidian | Level 7

It is doing left join on data

sas_Forum
Calcite | Level 5

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

LinusH
Tourmaline | Level 20

Yes

Data never sleeps
Vish33
Lapis Lazuli | Level 10

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

in simple term LEFT JOIN

Haikuo
Onyx | Level 15

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

Vish33
Lapis Lazuli | Level 10

Haikuo,

Thanks for info...that was a blind mistake of mine..:)

Patrick
Opal | Level 21

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1417 views
  • 0 likes
  • 7 in conversation