<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic SQL Joins and DATA Step Merges Comparison in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SQL-Joins-and-DATA-Step-Merges-Comparison/m-p/683100#M206855</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;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 &amp;nbsp;both merge and sql join gives same output as shown in below example?&lt;/P&gt;&lt;P&gt;Thanks a lot in advance!&lt;/P&gt;&lt;P&gt;/******************************************************/&lt;/P&gt;&lt;DIV&gt;data table1; input X A$ @@; cards;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;2 a1 2 a2&lt;/DIV&gt;&lt;DIV&gt;; run;&lt;/DIV&gt;&lt;DIV&gt;data table2; input X B$ @@; cards;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;2 b1 2 b2&lt;/DIV&gt;&lt;DIV&gt;; run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;proc sort data=table1;by X;run;&lt;/DIV&gt;&lt;DIV&gt;proc sort data=table2;by X;run;&lt;/DIV&gt;&lt;DIV&gt;data merged;&lt;/DIV&gt;&lt;DIV&gt;merge table1 table2;&lt;/DIV&gt;&lt;DIV&gt;by X;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;proc print data=table1 noobs; title 'Table1'; run;&lt;/DIV&gt;&lt;DIV&gt;proc print data=table2 noobs; title 'Table2'; run;&lt;/DIV&gt;&lt;DIV&gt;proc print data=merged noobs; title 'Merge Data'; run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;proc sql; title 'SQL Join Data';&lt;/DIV&gt;&lt;DIV&gt;select coalesce(a.X, b.X) label='G3', A, B&lt;/DIV&gt;&lt;DIV&gt;from table1 as a full join table2 as b&lt;/DIV&gt;&lt;DIV&gt;on a.X = b.X ;&lt;/DIV&gt;&lt;DIV&gt;quit;&lt;/DIV&gt;&lt;DIV&gt;&lt;P&gt;/******************************************************/&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Thu, 10 Sep 2020 22:02:47 GMT</pubDate>
    <dc:creator>tpchaudhary</dc:creator>
    <dc:date>2020-09-10T22:02:47Z</dc:date>
    <item>
      <title>SQL Joins and DATA Step Merges Comparison</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Joins-and-DATA-Step-Merges-Comparison/m-p/683100#M206855</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;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 &amp;nbsp;both merge and sql join gives same output as shown in below example?&lt;/P&gt;&lt;P&gt;Thanks a lot in advance!&lt;/P&gt;&lt;P&gt;/******************************************************/&lt;/P&gt;&lt;DIV&gt;data table1; input X A$ @@; cards;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;2 a1 2 a2&lt;/DIV&gt;&lt;DIV&gt;; run;&lt;/DIV&gt;&lt;DIV&gt;data table2; input X B$ @@; cards;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;2 b1 2 b2&lt;/DIV&gt;&lt;DIV&gt;; run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;proc sort data=table1;by X;run;&lt;/DIV&gt;&lt;DIV&gt;proc sort data=table2;by X;run;&lt;/DIV&gt;&lt;DIV&gt;data merged;&lt;/DIV&gt;&lt;DIV&gt;merge table1 table2;&lt;/DIV&gt;&lt;DIV&gt;by X;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;proc print data=table1 noobs; title 'Table1'; run;&lt;/DIV&gt;&lt;DIV&gt;proc print data=table2 noobs; title 'Table2'; run;&lt;/DIV&gt;&lt;DIV&gt;proc print data=merged noobs; title 'Merge Data'; run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;proc sql; title 'SQL Join Data';&lt;/DIV&gt;&lt;DIV&gt;select coalesce(a.X, b.X) label='G3', A, B&lt;/DIV&gt;&lt;DIV&gt;from table1 as a full join table2 as b&lt;/DIV&gt;&lt;DIV&gt;on a.X = b.X ;&lt;/DIV&gt;&lt;DIV&gt;quit;&lt;/DIV&gt;&lt;DIV&gt;&lt;P&gt;/******************************************************/&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 10 Sep 2020 22:02:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Joins-and-DATA-Step-Merges-Comparison/m-p/683100#M206855</guid>
      <dc:creator>tpchaudhary</dc:creator>
      <dc:date>2020-09-10T22:02:47Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Joins and DATA Step Merges Comparison</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Joins-and-DATA-Step-Merges-Comparison/m-p/683128#M206878</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/85580"&gt;@tpchaudhary&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;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 &amp;nbsp;both merge and sql join gives same output as shown in below example?&lt;/P&gt;
&lt;P&gt;Thanks a lot in advance!&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Are you saying that the guide is claiming that the two results in your program should be identical?&amp;nbsp; That I can't believe.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If these really are the exact programs in the guide, then let us know what the page 84 says about the results.&amp;nbsp; 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.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2020 00:51:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Joins-and-DATA-Step-Merges-Comparison/m-p/683128#M206878</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-09-11T00:51:06Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Joins and DATA Step Merges Comparison</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Joins-and-DATA-Step-Merges-Comparison/m-p/683350#M206960</link>
      <description>&lt;P&gt;Hi There, &amp;nbsp;Under same topic (P. 84) in book &amp;nbsp;page 87 it says, "&lt;EM&gt;When you add the COALESCE function to the SELECT clause of the PROC SQL outer join, the PROC&amp;nbsp;SQL outer join can produce the same result as a DATA step match-merge.&lt;/EM&gt;" 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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Also, can someone suggest me how we can get same result for this particular example in merge and sql both?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Exact book example from page 87 &amp;amp; 88 shown below:&lt;/P&gt;&lt;P&gt;/****************************************************************/&lt;/P&gt;&lt;DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Book Example.png" style="width: 670px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49293iA8BB75FBE8D47C68/image-size/large?v=v2&amp;amp;px=999" role="button" title="Book Example.png" alt="Book Example.png" /&gt;&lt;/span&gt;&lt;/DIV&gt;&lt;DIV&gt;/*DATA Step Match-Merge */&lt;/DIV&gt;&lt;DIV&gt;/*Below I created the table 3 and 4 unless someone don't have table access*/&lt;/DIV&gt;&lt;DIV&gt;data Three; input X A$ @@; cards;&lt;/DIV&gt;&lt;DIV&gt;1 a1 1 a2 2 b1 2 b2 4 d&lt;/DIV&gt;&lt;DIV&gt;;run;&lt;/DIV&gt;&lt;DIV&gt;data Four; input X B$ @@; cards;&lt;/DIV&gt;&lt;DIV&gt;2 x1 2 x2 3 y 5 v&lt;/DIV&gt;&lt;DIV&gt;;run;&lt;/DIV&gt;&lt;P&gt;/***************************************************************************/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2020 19:59:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Joins-and-DATA-Step-Merges-Comparison/m-p/683350#M206960</guid>
      <dc:creator>tpchaudhary</dc:creator>
      <dc:date>2020-09-11T19:59:53Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Joins and DATA Step Merges Comparison</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Joins-and-DATA-Step-Merges-Comparison/m-p/683351#M206961</link>
      <description>&lt;P&gt;&lt;EM&gt;the PROC&amp;nbsp;SQL outer join &lt;STRONG&gt;can&lt;/STRONG&gt; produce the same result as a DATA step match-merge.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(emphasis by me)&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2020 20:07:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Joins-and-DATA-Step-Merges-Comparison/m-p/683351#M206961</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-11T20:07:01Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Joins and DATA Step Merges Comparison</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Joins-and-DATA-Step-Merges-Comparison/m-p/683363#M206969</link>
      <description>Thanks Kurt for clarifying that, "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."&lt;BR /&gt;&lt;BR /&gt;In this situation example is right, and because of many to many relationship both merge and sql join can't give same results.&lt;BR /&gt;Thanks a lot!</description>
      <pubDate>Fri, 11 Sep 2020 21:12:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Joins-and-DATA-Step-Merges-Comparison/m-p/683363#M206969</guid>
      <dc:creator>tpchaudhary</dc:creator>
      <dc:date>2020-09-11T21:12:14Z</dc:date>
    </item>
  </channel>
</rss>

