<?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 Re: Merge and SQL in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merge-and-SQL/m-p/301239#M20476</link>
    <description>&lt;P&gt;Your SQL code won't execute, as # is not allowed in SAS names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is a basic difference between SQL and the datastep merge, when there is a m:n relationship between the datasets. SQL will yield m*n records, while the merge will yield max(m,n) records. So you need to inspect both datasets for multiple occurences of a key variable combination.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The condition&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if uio or bnm;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;suggests you should be trying an outer join.&lt;/P&gt;</description>
    <pubDate>Wed, 28 Sep 2016 12:33:26 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2016-09-28T12:33:26Z</dc:date>
    <item>
      <title>Merge and SQL</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merge-and-SQL/m-p/301237#M20475</link>
      <description>&lt;P&gt;Hello Team,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working on one of migration and has below statement&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data strat.rep3;&lt;BR /&gt;merge strat.rep1 (in=uio) strat.rep2 (in=bnm);&lt;BR /&gt;by wclientcode wGroup mth ptpgroup;&lt;BR /&gt;if uio or bnm;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone please guide me what can be possible SQL statement for same ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SELECT #rep1.wClientCode, #rep1.wGroup, #rep1.mth, #rep1.ptpGroup, #rep1.no_docapt, #rep1.ptpamtcapt,&lt;BR /&gt;#rep2.ptpamtdue, #rep2.no_kept, #rep2.ptpkeptamt, #rep2.no_dodue&lt;BR /&gt;FROM #rep1 INNER JOIN #rep2&lt;BR /&gt;ON #rep1.wClientCode = #rep2.wClientCode&lt;BR /&gt;AND #rep1.wGroup = #rep2.wGroup&lt;BR /&gt;AND #rep1.mth = #rep2.mth&lt;BR /&gt;AND #rep1.ptpGroup = #rep2.ptpGroup&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But this statement not matching records of SAS output and SQL output. Can someone please guide me what is wrong here ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let me know&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 28 Sep 2016 12:25:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merge-and-SQL/m-p/301237#M20475</guid>
      <dc:creator>yudhishtirb</dc:creator>
      <dc:date>2016-09-28T12:25:52Z</dc:date>
    </item>
    <item>
      <title>Re: Merge and SQL</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merge-and-SQL/m-p/301239#M20476</link>
      <description>&lt;P&gt;Your SQL code won't execute, as # is not allowed in SAS names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is a basic difference between SQL and the datastep merge, when there is a m:n relationship between the datasets. SQL will yield m*n records, while the merge will yield max(m,n) records. So you need to inspect both datasets for multiple occurences of a key variable combination.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The condition&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if uio or bnm;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;suggests you should be trying an outer join.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Sep 2016 12:33:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merge-and-SQL/m-p/301239#M20476</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-09-28T12:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: Merge and SQL</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merge-and-SQL/m-p/301247#M20478</link>
      <description>&lt;P&gt;Hi KurtBremser&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;Yes, its working with full outer join.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;So &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;if uio or bnm - Full Outer Join&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;&lt;SPAN&gt;if uio and bnm - Inner Join&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;&lt;SPAN&gt;if uio - Right&amp;nbsp;Join&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;&lt;SPAN&gt;If bnm - Left Join&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;&lt;SPAN&gt;Thank you&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Sep 2016 12:57:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merge-and-SQL/m-p/301247#M20478</guid>
      <dc:creator>yudhishtirb</dc:creator>
      <dc:date>2016-09-28T12:57:46Z</dc:date>
    </item>
    <item>
      <title>Re: Merge and SQL</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merge-and-SQL/m-p/301248#M20479</link>
      <description>&lt;P&gt;Make sure to check results in the case of a Manu to many merge. If this isn't an issue with your data feel free to disregard this.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Sep 2016 13:09:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merge-and-SQL/m-p/301248#M20479</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-09-28T13:09:03Z</dc:date>
    </item>
  </channel>
</rss>

