DATA Step, Macro, Functions and more

Merge and Full join

Accepted Solution Solved
Reply
Super Contributor
Posts: 673
Accepted Solution

Merge and Full join

I used the following two methods and found out there is difference in number of records for each method:

data x;

merge SASDATA.TU_LAIDC_APAC(in=a) SASDATA.TU_LAIDC_APAC_corp(in=b);

by id;

if a or b;

run;

The above results in 154718 records.

when I use the following:

proc sql;

create table xx as

select  coalesce(a.id,b.id) as id

from SASDATA.TU_LAIDC_APAC a  full outer join SASDATA.TU_LAIDC_APAC_corp b

on a.id=b.id;

quit;

This one results in 155047 records.

where could be the difference?


Accepted Solutions
Solution
‎10-03-2013 08:07 PM
SAS Employee
Posts: 11

Re: Merge and Full join

you probably have some id va.uess with 2 or more rows in both datasets. suppose you have id=99 twice in both datasets - SQL will form the cartesian join of these (4 output records).  datastep will advance  each by group until the end of the shorter one, and then hold that row until the end of the longer one (2 output records)

View solution in original post


All Replies
Solution
‎10-03-2013 08:07 PM
SAS Employee
Posts: 11

Re: Merge and Full join

you probably have some id va.uess with 2 or more rows in both datasets. suppose you have id=99 twice in both datasets - SQL will form the cartesian join of these (4 output records).  datastep will advance  each by group until the end of the shorter one, and then hold that row until the end of the longer one (2 output records)

🔒 This topic is solved and locked.

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

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