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.

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
  • 1 reply
  • 1142 views
  • 1 like
  • 2 in conversation