DATA Step, Macro, Functions and more

Merge and proc sql left join merge diffrence

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 19
Accepted Solution

Merge and proc sql left join merge diffrence

[ Edited ]

Hi,

 

 

Hi,

What the diffrence between this two merging ways, both of them give me diffrent num of rows(2561984 and 2561938 ),

 

 

data wyn22;
merge skzr1(in=zb1) krel;
by id_klienta;
id_cst=coalesce(id_klienta_rel, id_klienta);
if zb1=1 then output;
run;

 

Thanks.


proc sql;
create table wyn22_1 as
select skzr1.*, krel.*, coalesce(id_klienta_rel, skzr1.id_klienta) as id_cst from
skzr1 left join krel
on skzr1.id_klienta=krel.id_klienta;
quit;


Accepted Solutions
Solution
Friday
Super User
Posts: 6,928

Re: Merge and proc sql left join merge diffrence

When you have three matches in one dataset and two in the other (for a given condition), the data step merge will result in three observations (the values fronm the second observation in the second dataset will show up in the second and third match), while SQL will result in six observations (all combinations). The SQL result is called a cartesian join.

With a data step, you will also get a NOTE in the log notfiying you that more than one dataset contains multiple matches, as that is often not intended.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
Friday
Super User
Posts: 6,928

Re: Merge and proc sql left join merge diffrence

When you have three matches in one dataset and two in the other (for a given condition), the data step merge will result in three observations (the values fronm the second observation in the second dataset will show up in the second and third match), while SQL will result in six observations (all combinations). The SQL result is called a cartesian join.

With a data step, you will also get a NOTE in the log notfiying you that more than one dataset contains multiple matches, as that is often not intended.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 90 views
  • 1 like
  • 2 in conversation