<?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 proc sql optimisation in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-optimisation/m-p/46910#M12519</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't think it would make much, if any, difference.&amp;nbsp; At least it hasn't, consistently, on any of my own tests.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 28 Mar 2012 13:48:38 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2012-03-28T13:48:38Z</dc:date>
    <item>
      <title>proc sql optimisation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-optimisation/m-p/46909#M12518</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to optimise my proc sql to be as efficient as it can be.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm matching a large dataset onto a performance file, but the rows selected with change each month depending on the outcome window.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc sql is processed in the following order (I think)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9pt; font-family: 'Courier New';"&gt;proc sql;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9pt; font-family: 'Courier New';"&gt;select ...&lt;/SPAN&gt;&lt;SPAN style="font-size: 9pt; font-family: Wingdings2;"&gt;5&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9pt; font-family: 'Courier New';"&gt;from ...&lt;/SPAN&gt;&lt;SPAN style="font-size: 9pt; font-family: Wingdings2;"&gt;1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9pt; font-family: 'Courier New';"&gt;where ...&lt;/SPAN&gt;&lt;SPAN style="font-size: 9pt; font-family: Wingdings2;"&gt;2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9pt; font-family: 'Courier New';"&gt;group by ...&lt;/SPAN&gt;&lt;SPAN style="font-size: 9pt; font-family: Wingdings2;"&gt;3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9pt; font-family: 'Courier New';"&gt;having ...&lt;/SPAN&gt;&lt;SPAN style="font-size: 9pt; font-family: Wingdings2;"&gt;4&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9pt; font-family: 'Courier New';"&gt;order by ...;&lt;/SPAN&gt;&lt;SPAN style="font-size: 9pt; font-family: Wingdings2;"&gt;6&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9pt; font-family: 'Courier New';"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9pt; font-family: 'Courier New';"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9pt; font-family: 'Courier New';"&gt;For efficiency, would it be better to have a where statement in the from line?&amp;nbsp; Would this get processed first?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9pt; font-family: 'Courier New';"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9pt; font-family: 'Courier New';"&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 9pt; font-family: 'Courier New';"&gt;C&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Mar 2012 13:34:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-optimisation/m-p/46909#M12518</guid>
      <dc:creator>speaky</dc:creator>
      <dc:date>2012-03-28T13:34:34Z</dc:date>
    </item>
    <item>
      <title>proc sql optimisation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-optimisation/m-p/46910#M12519</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't think it would make much, if any, difference.&amp;nbsp; At least it hasn't, consistently, on any of my own tests.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Mar 2012 13:48:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-optimisation/m-p/46910#M12519</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-03-28T13:48:38Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql optimisation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-optimisation/m-p/46911#M12520</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure I completely understand your question, but here is my 2 cents:&lt;/P&gt;&lt;P&gt;1. 'where' clause is processed even before 'select' clause in term of processing.&lt;/P&gt;&lt;P&gt;2. Sometimes you can't change the writting orders, and in this case, it does not matter anyway.&lt;/P&gt;&lt;P&gt;3. SQL is very efficient if you do it completely natively, say within Oracle by pass-through method.&lt;/P&gt;&lt;P&gt;4. if your datasets are SAS tables, you could explore other options, such as data step merge, or with index, or hash(), it can only be determined on case by case bases.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A good summary paper on 9 ways of joining datasets:&lt;/P&gt;&lt;P&gt;&lt;A class="jive-link-external-small" href="http://www.nesug.org/Proceedings/nesug09/po/po13.pdf"&gt;http://www.nesug.org/Proceedings/nesug09/po/po13.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Mar 2012 13:53:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-optimisation/m-p/46911#M12520</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-03-28T13:53:05Z</dc:date>
    </item>
    <item>
      <title>proc sql optimisation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-optimisation/m-p/46912#M12521</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for your replies!&amp;nbsp; :O)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm doing a left join onto a performance table and restricting by outcome month, but the performance file will get very large over time.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My question was around the location of the where clause, at present it's in the where select at the bottom, but I wondered if anyone knew for efficiency if it was better to put this after the table reference in the from statement?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code below worked using ODBC, but when I run it in enterprise guide it gives a syntax error for the and line - is this because there is more than one variable in the select statement?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At the moment, the datasets are very small, but when we switch portfolio, optimising the code below is key!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;sql&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; color: black; font-family: 'Courier New'; background-color: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-size: 10pt; color: blue; font-family: 'Courier New'; background-color: white;"&gt;create&lt;/SPAN&gt; &lt;SPAN style="font-size: 10pt; color: blue; font-family: 'Courier New'; background-color: white;"&gt;table&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: black; font-family: 'Courier New'; background-color: white;"&gt; cj &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: blue; font-family: 'Courier New'; background-color: white;"&gt;as&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-size: 10pt; color: blue; font-family: 'Courier New'; background-color: white;"&gt;select&lt;/SPAN&gt; &lt;SPAN style="font-size: 10pt; color: teal; font-family: 'Courier New'; background-color: white;"&gt;A.&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: black; font-family: 'Courier New'; background-color: white;"&gt;*, &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: teal; font-family: 'Courier New'; background-color: white;"&gt;B.&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: black; font-family: 'Courier New'; background-color: white;"&gt;*&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10pt; color: blue; font-family: 'Courier New'; background-color: white;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: black; font-family: 'Courier New'; background-color: white;"&gt; &amp;amp;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: teal; font-family: 'Courier New'; background-color: white;"&gt;mthy.&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: black; font-family: 'Courier New'; background-color: white;"&gt; a &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: blue; font-family: 'Courier New'; background-color: white;"&gt;left&lt;/SPAN&gt; &lt;SPAN style="font-size: 10pt; color: blue; font-family: 'Courier New'; background-color: white;"&gt;join&lt;/SPAN&gt; &lt;SPAN style="font-size: 10pt; color: teal; font-family: 'Courier New'; background-color: white;"&gt;perform.&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: black; font-family: 'Courier New'; background-color: white;"&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: teal; font-family: 'Courier New'; background-color: white;"&gt;perf_file.&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: black; font-family: 'Courier New'; background-color: white;"&gt; b&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10pt; color: blue; font-family: 'Courier New'; background-color: white;"&gt;on&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: black; font-family: 'Courier New'; background-color: white;"&gt; a.cs_id = b.cs_id&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10pt; color: blue; font-family: 'Courier New'; background-color: white;"&gt;and&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: black; font-family: 'Courier New'; background-color: white;"&gt; (cs_id, arrears) &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: blue; font-family: 'Courier New'; background-color: white;"&gt;IN&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; color: black; font-family: 'Courier New'; background-color: white;"&gt;&amp;nbsp; (&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: blue; font-family: 'Courier New'; background-color: white;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: black; font-family: 'Courier New'; background-color: white;"&gt; cs_id, MAX(arrears) &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: blue; font-family: 'Courier New'; background-color: white;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: black; font-family: 'Courier New'; background-color: white;"&gt; flag_3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10pt; color: blue; font-family: 'Courier New'; background-color: white;"&gt;from&lt;/SPAN&gt; &lt;SPAN style="font-size: 10pt; color: teal; font-family: 'Courier New'; background-color: white;"&gt;perform.&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: black; font-family: 'Courier New'; background-color: white;"&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: teal; font-family: 'Courier New'; background-color: white;"&gt;perf_file.&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: black; font-family: 'Courier New'; background-color: white;"&gt; b&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10pt; color: blue; font-family: 'Courier New'; background-color: white;"&gt;where&lt;/SPAN&gt; &lt;STRONG style="color: teal; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;'01DEC2011'D&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; color: black; font-family: 'Courier New'; background-color: white;"&gt; &amp;lt;= B.outcome_month &amp;lt;= &lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;'28FEB2012'D&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10pt; color: blue; font-family: 'Courier New'; background-color: white;"&gt;group&lt;/SPAN&gt; &lt;SPAN style="font-size: 10pt; color: blue; font-family: 'Courier New'; background-color: white;"&gt;by&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: black; font-family: 'Courier New'; background-color: white;"&gt; B.cs_id)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;QUIT&lt;/STRONG&gt;;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Mar 2012 15:45:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-optimisation/m-p/46912#M12521</guid>
      <dc:creator>speaky</dc:creator>
      <dc:date>2012-03-28T15:45:56Z</dc:date>
    </item>
  </channel>
</rss>

