<?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: Convert Merge to SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-Merge-to-SQL/m-p/548750#M152214</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;What i understand from your code is, you want to left join both the tables and want only those records for the first instance of the id.&lt;/P&gt;
&lt;P&gt;below is the code which can do it for you, you need to use your column names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table final as select *,monotonic() as rowid from test as a left join test1 as b 
on a.opbel=b.opbel
group by a.opbel
having rowid=min(calculated rowid);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 05 Apr 2019 12:29:14 GMT</pubDate>
    <dc:creator>Shivam</dc:creator>
    <dc:date>2019-04-05T12:29:14Z</dc:date>
    <item>
      <title>Convert Merge to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Merge-to-SQL/m-p/548727#M152206</link>
      <description>&lt;P&gt;Hi How do I convert the following merge code to SQL?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data SAP_Bill.erdo_main(sortedby=opbel);
        merge   SAP_Bill.erdo_max
  SAP_Bill.erdk(in=a);
        by              opbel;
        label   erdk_frei_am='Invoice_Release_Date';
        if a and first.opbel then output;
run;&lt;/PRE&gt;&lt;P&gt;I have included the names bwlow&amp;nbsp;of the columns from the input tables and the output table, i would like the SQL code to have the same Output&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Erdo_Max Table (Input)&lt;/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D&gt;&lt;TD&gt;erdk_frei_am&lt;/TD&gt;&lt;TD&gt;intopbel&lt;/TD&gt;&lt;TD&gt;vkont&lt;/TD&gt;&lt;TD&gt;total_amnt&lt;/TD&gt;&lt;TD&gt;budat&lt;/TD&gt;&lt;TD&gt;simulated&lt;/TD&gt;&lt;TD&gt;stokz&lt;/TD&gt;&lt;TD&gt;tobreleasd&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks In Advance&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2019 11:07:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Merge-to-SQL/m-p/548727#M152206</guid>
      <dc:creator>zdassu</dc:creator>
      <dc:date>2019-04-05T11:07:37Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Merge to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Merge-to-SQL/m-p/548736#M152207</link>
      <description>&lt;P&gt;If you have a working and tested data-step, don't waste your time to convert it to sql. I don't know any case in which sql performed better.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2019 11:00:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Merge-to-SQL/m-p/548736#M152207</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-04-05T11:00:03Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Merge to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Merge-to-SQL/m-p/548737#M152208</link>
      <description>&lt;P&gt;Hi I agree, However I have to convert this to SQL because i have to re-write the Scripts in Hadoop&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2019 11:04:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Merge-to-SQL/m-p/548737#M152208</guid>
      <dc:creator>zdassu</dc:creator>
      <dc:date>2019-04-05T11:04:30Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Merge to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Merge-to-SQL/m-p/548741#M152210</link>
      <description>&lt;P&gt;Why are you trying to elemental SAS?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2019 11:30:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Merge-to-SQL/m-p/548741#M152210</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2019-04-05T11:30:25Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Merge to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Merge-to-SQL/m-p/548748#M152213</link>
      <description>&lt;P&gt;Our Servers are moving from SAS server to a Hadoop Server&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2019 12:13:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Merge-to-SQL/m-p/548748#M152213</guid>
      <dc:creator>zdassu</dc:creator>
      <dc:date>2019-04-05T12:13:34Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Merge to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Merge-to-SQL/m-p/548750#M152214</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;What i understand from your code is, you want to left join both the tables and want only those records for the first instance of the id.&lt;/P&gt;
&lt;P&gt;below is the code which can do it for you, you need to use your column names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table final as select *,monotonic() as rowid from test as a left join test1 as b 
on a.opbel=b.opbel
group by a.opbel
having rowid=min(calculated rowid);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Apr 2019 12:29:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Merge-to-SQL/m-p/548750#M152214</guid>
      <dc:creator>Shivam</dc:creator>
      <dc:date>2019-04-05T12:29:14Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Merge to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Merge-to-SQL/m-p/548754#M152216</link>
      <description>&lt;P&gt;There is no way for SQL to replicate this logic, with a 100% guarantee.&amp;nbsp; SQL makes no promises as to the order of the incoming observations, thus any tool that looks for the first observation might produce a different result in SQL vs. SAS (or even on different SQL runs of the same program).&amp;nbsp; That includes the monotonic function.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you will keep SAS on at least one server, what you can do is this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data SAP_Bill.erdo_main (sortedby=opbel) / view=SAP_Bill.ordo_main;
   merge SAP_Bill.ordo_max SAP_Bil.erdk (in=a);
   by opbel;
   label erdk_frei_am='Invoice_Release_Date';
   if a abnd first.opbel then output;
run&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That's the same program, but using a view instead of a data set.&amp;nbsp; Then later:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   create table somewhere_on_hadoop as 
   select * from SAP_Bill.erdo_main;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I'm not sure if that's helpful or not, since it still requires SAS.&amp;nbsp; But there is no way that I know of to have SQL guarantee which observation will be "first" within a group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2019 13:07:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Merge-to-SQL/m-p/548754#M152216</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-04-05T13:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Merge to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Merge-to-SQL/m-p/550151#M152747</link>
      <description>&lt;P&gt;Hi I am a little confused how the code works, where would I put my column names&lt;/P&gt;</description>
      <pubDate>Thu, 11 Apr 2019 09:04:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Merge-to-SQL/m-p/550151#M152747</guid>
      <dc:creator>zdassu</dc:creator>
      <dc:date>2019-04-11T09:04:09Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Merge to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Merge-to-SQL/m-p/550152#M152748</link>
      <description>&lt;P&gt;Unfortunately, I am unable to access the SAS Server from Hadoop&lt;/P&gt;</description>
      <pubDate>Thu, 11 Apr 2019 09:05:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Merge-to-SQL/m-p/550152#M152748</guid>
      <dc:creator>zdassu</dc:creator>
      <dc:date>2019-04-11T09:05:00Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Merge to SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Merge-to-SQL/m-p/550168#M152749</link>
      <description>&lt;P&gt;columns are being selected by *(all columns) if you want to specify only few columns, then specify the names in place of *&lt;/P&gt;</description>
      <pubDate>Thu, 11 Apr 2019 11:04:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Merge-to-SQL/m-p/550168#M152749</guid>
      <dc:creator>Shivam</dc:creator>
      <dc:date>2019-04-11T11:04:29Z</dc:date>
    </item>
  </channel>
</rss>

