<?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: data step merging - converting to proc sql help in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/data-step-merging-converting-to-proc-sql-help/m-p/406414#M98960</link>
    <description>&lt;P&gt;Thanks Reeza for valuable suggestion. I will try to see if this works as well.&lt;/P&gt;</description>
    <pubDate>Mon, 23 Oct 2017 04:10:26 GMT</pubDate>
    <dc:creator>buddha_d</dc:creator>
    <dc:date>2017-10-23T04:10:26Z</dc:date>
    <item>
      <title>data step merging - converting to proc sql help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-merging-converting-to-proc-sql-help/m-p/406406#M98953</link>
      <description>&lt;P&gt;SAS gurus, I need help with proc sql code. I have to merge 4 datasets and I have the following code in datastep. I heard that proc sql doesn't require sorting step. If that is the case then I think I can put below 4 data steps in a single proc sql code. I underlined and italicized the steps I did.&lt;/P&gt;
&lt;P&gt;Can any one help me with this please. Thanks in advance !!!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; temp;&lt;/P&gt;
&lt;P&gt;merge data1 (in=ina) data2(in=inb);&lt;/P&gt;
&lt;P&gt;by id regiment_number serial_number;&lt;/P&gt;
&lt;P&gt;if ina ;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;EM&gt;1.sort data temp by lab_grade&lt;/EM&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;EM&gt;2.sort data temp1 by lab_grade then merge with temp.&lt;/EM&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; temp2 ;&lt;/P&gt;
&lt;P&gt;merge temp (in=ina) temp1 (in=inb);&lt;/P&gt;
&lt;P&gt;by lab_grade ;&lt;/P&gt;
&lt;P&gt;if ina and not inb then lab_grade='N/A';&lt;/P&gt;
&lt;P&gt;if ina then output;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;EM&gt;3.I need to merge temp2 (commercial_grade) dataset to temp3 with commercial_grade. I sorted temp2 and temp3 with commercial_grade.&lt;/EM&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; temp4 ;&lt;/P&gt;
&lt;P&gt;merge temp2 (in=ina) temp3 (in=inb);&lt;/P&gt;
&lt;P&gt;by commercial_grade ;&lt;/P&gt;
&lt;P&gt;if ina and not inb then commercial_grade='N/A';&lt;/P&gt;
&lt;P&gt;if ina then output;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 01:08:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-merging-converting-to-proc-sql-help/m-p/406406#M98953</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2017-10-23T01:08:02Z</dc:date>
    </item>
    <item>
      <title>Re: data step merging - converting to proc sql help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-merging-converting-to-proc-sql-help/m-p/406409#M98955</link>
      <description>&lt;P&gt;I do not know all the column names of data1, data2, temp1 and temp3 so I have to assume that&amp;nbsp;&lt;/P&gt;
&lt;P&gt;commercial_grade and lab_grade also present in data1&amp;nbsp; table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You also need to correct the select clause,enter the column name in select clause as you needed in final table temp4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table temp4 as&lt;BR /&gt;select a.*,b.*, &lt;BR /&gt;case when c.lab_grade is null then 'N/A' else c.lab_grade end as lab_grade,&lt;BR /&gt;case when d.commercial_grade is null then 'N/A' else d.commercial_grade end as commercial_grade&lt;BR /&gt;from data1 a left join data2 b on a.id=b.id and a.regiment_number=b.regiment_number and a.serial_number=b.serial_number&lt;BR /&gt;left join temp1 c on a.lab_grade= c.lab_grade&lt;BR /&gt;left join temp3 d on a.commercial_grade = d.commerical_grade;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: Added comma after lab_grade - PG&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 03:57:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-merging-converting-to-proc-sql-help/m-p/406409#M98955</guid>
      <dc:creator>RahulG</dc:creator>
      <dc:date>2017-10-23T03:57:48Z</dc:date>
    </item>
    <item>
      <title>Re: data step merging - converting to proc sql help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-merging-converting-to-proc-sql-help/m-p/406410#M98956</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/139130"&gt;@buddha_d&lt;/a&gt; just because you don't have to sort the datasets does not mean, that sas does not sort them when you use proc sql.&lt;BR /&gt;The proc sql posted by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1751"&gt;@RahulG&lt;/a&gt; may solve the problem, but it is less easy to read (at least for me at 5:42 am) and by far less easy to debug.</description>
      <pubDate>Mon, 23 Oct 2017 03:44:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-merging-converting-to-proc-sql-help/m-p/406410#M98956</guid>
      <dc:creator>error_prone</dc:creator>
      <dc:date>2017-10-23T03:44:32Z</dc:date>
    </item>
    <item>
      <title>Re: data step merging - converting to proc sql help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-merging-converting-to-proc-sql-help/m-p/406411#M98957</link>
      <description>&lt;P&gt;Rahul,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; I am sorry that I wasn't very clear in my previous post. lab_grade and commercial_grade are in data2 (not data1). I supposed the code might change? correct me if I am wrong?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for taking time to write me.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 03:49:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-merging-converting-to-proc-sql-help/m-p/406411#M98957</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2017-10-23T03:49:47Z</dc:date>
    </item>
    <item>
      <title>Re: data step merging - converting to proc sql help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-merging-converting-to-proc-sql-help/m-p/406412#M98958</link>
      <description>thanks error_prone for the suggestion</description>
      <pubDate>Mon, 23 Oct 2017 03:50:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-merging-converting-to-proc-sql-help/m-p/406412#M98958</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2017-10-23T03:50:21Z</dc:date>
    </item>
    <item>
      <title>Re: data step merging - converting to proc sql help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-merging-converting-to-proc-sql-help/m-p/406413#M98959</link>
      <description>&lt;P&gt;Write your SQL steps one by one.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First determine the type of join needed, one to one, one to many and then if its a left/right/inner join. Do that for each table first. Drawing it out is the easiest way.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have access to EG, using Query Builder is a good way to visualize it. Start with replicating your first proc, make sure the results are the same and then move on to the next. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 03:55:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-merging-converting-to-proc-sql-help/m-p/406413#M98959</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-23T03:55:01Z</dc:date>
    </item>
    <item>
      <title>Re: data step merging - converting to proc sql help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-merging-converting-to-proc-sql-help/m-p/406414#M98960</link>
      <description>&lt;P&gt;Thanks Reeza for valuable suggestion. I will try to see if this works as well.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 04:10:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-merging-converting-to-proc-sql-help/m-p/406414#M98960</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2017-10-23T04:10:26Z</dc:date>
    </item>
  </channel>
</rss>

