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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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