Hi All,
As it is explained in SAS certified professional prep gide for advance programming using SAS 9.4 in chapt.3 on page 84 under section "Comparing SQL Joins and DATA Step Match-Merges", my results in below example isn't giving same result. Can someone explain me about why not both merge and sql join gives same output as shown in below example?
Thanks a lot in advance!
/******************************************************/
/******************************************************/
the PROC SQL outer join can produce the same result as a DATA step match-merge.
(emphasis by me)
A data step match merge will only create the same result as the SQL join when you have a one-to-one or one-to-many relationship; with many-to-many, the results will always differ.
What the book wants to say is that, in a certain match, the COALESCE function will create the same value overwrite sequence that the data step does. In SQL, the COALESCE function does it, in the DATA step, the sequence in which observations are read into the PDV.
@tpchaudhary wrote:
Hi All,
As it is explained in SAS certified professional prep gide for advance programming using SAS 9.4 in chapt.3 on page 84 under section "Comparing SQL Joins and DATA Step Match-Merges", my results in below example isn't giving same result. Can someone explain me about why not both merge and sql join gives same output as shown in below example?
Thanks a lot in advance!
Are you saying that the guide is claiming that the two results in your program should be identical? That I can't believe.
If these really are the exact programs in the guide, then let us know what the page 84 says about the results. But if you are not using program examples in the guide, then I suspect there is a meaningful difference between the code in the guide and the code you have created to replicate it.
Hi There, Under same topic (P. 84) in book page 87 it says, "When you add the COALESCE function to the SELECT clause of the PROC SQL outer join, the PROC SQL outer join can produce the same result as a DATA step match-merge." Also, pretty much similar example is on page 88 in the book, which output also has same issue, but book claiming that it is combining rows in the same way.
I just want to understand that how it is combining same way because for the duplicate value for joining column (X) has only two row in merge output and four rows in sql join output.
Also, can someone suggest me how we can get same result for this particular example in merge and sql both?
Exact book example from page 87 & 88 shown below:
/****************************************************************/
/***************************************************************************/
the PROC SQL outer join can produce the same result as a DATA step match-merge.
(emphasis by me)
A data step match merge will only create the same result as the SQL join when you have a one-to-one or one-to-many relationship; with many-to-many, the results will always differ.
What the book wants to say is that, in a certain match, the COALESCE function will create the same value overwrite sequence that the data step does. In SQL, the COALESCE function does it, in the DATA step, the sequence in which observations are read into the PDV.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.