<?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 merge to sql conversion in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/merge-to-sql-conversion/m-p/408347#M99651</link>
    <description>&lt;P&gt;I have a merge statement which needs to be converted to a proc sql join,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data a.main;&lt;BR /&gt;merge main&lt;BR /&gt;a.proxy;&lt;BR /&gt;by id;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;which i wrote it as,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table a.main as&lt;BR /&gt;select * from main a join a.proxy b&lt;BR /&gt;on a.id=b.id;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now the tough part for me is, the data step has gone bit complex with parameters how do i replicate the same in proc sql ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data a.main;&lt;BR /&gt;merge main a.proxy&lt;BR /&gt;(drop=name&amp;nbsp;address&amp;nbsp;city pin_code&lt;BR /&gt;%if %eval(&amp;amp;ht2. IN XX YY ZZ) %then&lt;BR /&gt;%str(orig_name);&lt;BR /&gt;);&lt;BR /&gt;by id; run;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Sun, 29 Oct 2017 15:14:24 GMT</pubDate>
    <dc:creator>GunnerEP</dc:creator>
    <dc:date>2017-10-29T15:14:24Z</dc:date>
    <item>
      <title>merge to sql conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-to-sql-conversion/m-p/408347#M99651</link>
      <description>&lt;P&gt;I have a merge statement which needs to be converted to a proc sql join,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data a.main;&lt;BR /&gt;merge main&lt;BR /&gt;a.proxy;&lt;BR /&gt;by id;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;which i wrote it as,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table a.main as&lt;BR /&gt;select * from main a join a.proxy b&lt;BR /&gt;on a.id=b.id;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now the tough part for me is, the data step has gone bit complex with parameters how do i replicate the same in proc sql ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data a.main;&lt;BR /&gt;merge main a.proxy&lt;BR /&gt;(drop=name&amp;nbsp;address&amp;nbsp;city pin_code&lt;BR /&gt;%if %eval(&amp;amp;ht2. IN XX YY ZZ) %then&lt;BR /&gt;%str(orig_name);&lt;BR /&gt;);&lt;BR /&gt;by id; run;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Oct 2017 15:14:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-to-sql-conversion/m-p/408347#M99651</guid>
      <dc:creator>GunnerEP</dc:creator>
      <dc:date>2017-10-29T15:14:24Z</dc:date>
    </item>
    <item>
      <title>Re: merge to sql conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/merge-to-sql-conversion/m-p/408443#M99719</link>
      <description>&lt;P&gt;1- Your merge and join steps are not equivalent. See below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data T1; 
  X=1;
data T2; 
  X=2;
data J1; 
  merge T1 T2; 
  by X;
proc sql; 
  create table J2 as 
  select * 
  from T1 join T2 
   on T1.X=T2.X;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The SQL step only keeps common keys.&lt;/P&gt;
&lt;P&gt;The steps are only equivalent if all key values are common to both tables, and unique&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2- Just add the same option in your SQL.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;proc sql;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;create table a.main as&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;select * from main a join a.proxy(drop=name&amp;nbsp;address&amp;nbsp;city pin_code %if %eval(&amp;amp;ht2. IN XX YY ZZ) %then %str(orig_name)&amp;nbsp;)&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;b&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;on a.id=b.id;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2017 02:36:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/merge-to-sql-conversion/m-p/408443#M99719</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-10-30T02:36:41Z</dc:date>
    </item>
  </channel>
</rss>

