BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Matt3
Quartz | Level 8

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User

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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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