<?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: Optimise the sas  sql query in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Optimise-the-sas-sql-query/m-p/319063#M69986</link>
    <description>&lt;P&gt;Feel free to not supply the information requested and not get the help you want.&lt;/P&gt;</description>
    <pubDate>Wed, 14 Dec 2016 22:03:56 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2016-12-14T22:03:56Z</dc:date>
    <item>
      <title>Optimise the sas  sql query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimise-the-sas-sql-query/m-p/316866#M69302</link>
      <description>&lt;P&gt;Hello experts,&lt;/P&gt;
&lt;P&gt;Please, I want to optimise the sas sql query, for the hundred of variables and more than 3 000 000 observations.&lt;/P&gt;
&lt;P&gt;when I do like below, but , it will take more than 10 minutes&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;create table toto as&lt;/P&gt;
&lt;P&gt;select&lt;/P&gt;
&lt;P&gt;v1 as w1,&lt;/P&gt;
&lt;P&gt;v2,&lt;/P&gt;
&lt;P&gt;case&lt;/P&gt;
&lt;P&gt;...when&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;else&lt;/P&gt;
&lt;P&gt;as v3,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/* many cases conditions of case are used */...&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;..,&lt;/P&gt;
&lt;P&gt;vn&lt;/P&gt;
&lt;P&gt;from ( select * from dat1 where y1='O' and f1 ne 'E') as M1 left join beta as M2&lt;/P&gt;
&lt;P&gt;on M1.id=M2.id&lt;/P&gt;
&lt;P&gt;left join omega as M3&lt;/P&gt;
&lt;P&gt;on M2.tr=M3.tr;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;I think using merge with dataset ? will be more faster ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 22:20:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimise-the-sas-sql-query/m-p/316866#M69302</guid>
      <dc:creator>LineMoon</dc:creator>
      <dc:date>2016-12-05T22:20:12Z</dc:date>
    </item>
    <item>
      <title>Re: Optimise the sas  sql query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimise-the-sas-sql-query/m-p/316873#M69305</link>
      <description>&lt;P&gt;Assuming tables Beta and Omega don't have high volumes, a hash lookup could perform quite well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data toto;&lt;BR /&gt; set dat1(where=(y1='O' and f1 ne 'E'));&lt;/P&gt;
&lt;P&gt;if _n_=1 then&lt;/P&gt;
&lt;P&gt;do;&lt;/P&gt;
&lt;P&gt;...define hashes for Beta&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...hash lookups&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;... all your case statements reformulated as if..then..else or as Select ...When ..&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Dec 2016 03:32:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimise-the-sas-sql-query/m-p/316873#M69305</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-12-06T03:32:13Z</dc:date>
    </item>
    <item>
      <title>Re: Optimise the sas  sql query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimise-the-sas-sql-query/m-p/316874#M69306</link>
      <description>&lt;P&gt;You don't give much details about those CASE expressions. First try to remove the subquery like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;....
from 
	dat1 as M1 left join 
	beta as M2 on M1.id=M2.id left join 
	omega as M3 on M2.tr=M3.tr
where M1.y1='O' and M1.f1 ne 'E';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and if column&lt;STRONG&gt; tr&lt;/STRONG&gt; exists in table &lt;STRONG&gt;dat1&lt;/STRONG&gt;, you should use &lt;STRONG&gt;on M1.tr=M3.tr&lt;/STRONG&gt; instead of &lt;STRONG&gt;on M2.tr=M3.tr&lt;/STRONG&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 23:00:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimise-the-sas-sql-query/m-p/316874#M69306</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-12-05T23:00:32Z</dc:date>
    </item>
    <item>
      <title>Re: Optimise the sas  sql query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimise-the-sas-sql-query/m-p/316878#M69308</link>
      <description>&lt;P&gt;Depending on the CASE statements, a format could be helpful.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 23:24:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimise-the-sas-sql-query/m-p/316878#M69308</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-12-05T23:24:08Z</dc:date>
    </item>
    <item>
      <title>Re: Optimise the sas  sql query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimise-the-sas-sql-query/m-p/316926#M69320</link>
      <description>&lt;P&gt;Question about the subquery removal.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there any benefit to using a data set where parameter (as per&amp;nbsp;the program fragment below), as opposed to having the &lt;EM&gt;&lt;STRONG&gt;"where&amp;nbsp;m1.y1='0'&amp;nbsp;and&amp;nbsp;m1.f1&amp;nbsp;NE&amp;nbsp;'E'"&lt;/STRONG&gt;&lt;/EM&gt; sql clause?&amp;nbsp; In the DATA step world, this can often improve performance by outsourcing the filtering process&amp;nbsp;to the data access engine. Perhaps proc sql knows to outsource when feasible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  ....
from 
	dat1 (where=(y1='0'and f1 ^= 'E')) as M1 left join 
	beta as M2 on M1.id=M2.id left join 
	omega as M3 on M2.tr=M3.tr
    ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Dec 2016 04:31:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimise-the-sas-sql-query/m-p/316926#M69320</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2016-12-06T04:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: Optimise the sas  sql query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimise-the-sas-sql-query/m-p/316936#M69325</link>
      <description>&lt;P&gt;Using the where clause as a data set option or as a SQL clause should make no difference.&lt;/P&gt;
&lt;P&gt;It is a matter of preference, sticking to the standards if this matters, and legibility.&lt;/P&gt;
&lt;P&gt;I like the option when possible as it makes the contribution of each data set more obvious.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data steps sometimes do behave differently depending on whether a clause or an option is supplied, but they shouldn't, and this behaviour is a defect.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Dec 2016 05:47:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimise-the-sas-sql-query/m-p/316936#M69325</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-12-06T05:47:13Z</dc:date>
    </item>
    <item>
      <title>Re: Optimise the sas  sql query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimise-the-sas-sql-query/m-p/316975#M69345</link>
      <description>&lt;P&gt;Sounds to me like your data modelling is a failure to start with:&lt;BR /&gt;"&lt;SPAN&gt; for the hundred of variables"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Have never seen a good working system with so many variables, your select will be huge. &amp;nbsp;Doesn't matter how well you write code, if you input data is rubbish then the code will not work well.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Dec 2016 10:27:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimise-the-sas-sql-query/m-p/316975#M69345</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-12-06T10:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: Optimise the sas  sql query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimise-the-sas-sql-query/m-p/317230#M69419</link>
      <description>&lt;P&gt;@ll: Thank you all for your answer.&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/38862"&gt;@ll&lt;/a&gt;: Thank you all for your answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To pricise some points&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;gt; clause when in sas sql, the case, I use is like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: Courier New;"&gt; &lt;SPAN style="color: #0000ff;"&gt;case&lt;BR /&gt; &lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #0000ff;"&gt;when&lt;/SPAN&gt; v1 &amp;gt; &lt;SPAN style="color: #008080;"&gt;&lt;STRONG&gt;12&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff;"&gt;and&lt;/SPAN&gt; W1=&lt;SPAN style="color: #800080;"&gt;‘O’&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff;"&gt;then&lt;/SPAN&gt; &lt;SPAN style="color: #008080;"&gt;1&lt;/SPAN&gt;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #0000ff;"&gt;when&lt;/SPAN&gt; V2 &amp;gt;= &lt;SPAN style="color: #008080;"&gt;&lt;STRONG&gt;0&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff;"&gt;and&lt;/SPAN&gt; W2=&lt;SPAN style="color: #800080;"&gt;‘F’&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff;"&gt;then&lt;/SPAN&gt; &lt;STRONG&gt;&lt;SPAN style="color: #008080;"&gt;2&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: Courier New;"&gt;..... &lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #0000ff;"&gt;when&lt;/SPAN&gt; vn &amp;lt; &lt;SPAN style="color: #008080;"&gt;&lt;STRONG&gt;0&lt;/STRONG&gt;&lt;/SPAN&gt; or Hn not &lt;SPAN style="color: #0000ff;"&gt;in&lt;/SPAN&gt; (&lt;SPAN style="color: #800080;"&gt;‘1’&lt;/SPAN&gt;,&lt;SPAN style="color: #800080;"&gt;‘2’&lt;/SPAN&gt;) &lt;SPAN style="color: #0000ff;"&gt;then&lt;/SPAN&gt; .&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="color: #0000ff;"&gt; else&lt;/SPAN&gt; &lt;SPAN style="color: #008080;"&gt;&lt;STRONG&gt;100&lt;BR /&gt; &lt;/STRONG&gt;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="color: #0000ff;"&gt; end as&lt;/SPAN&gt; w_n&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: Courier New;"&gt;I use it with left join.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: Courier New;"&gt;I want to have a real time cpu &amp;lt;1 minutes, now I have 10 minutes.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: Courier New;"&gt;Thank you again&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2016 07:45:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimise-the-sas-sql-query/m-p/317230#M69419</guid>
      <dc:creator>LineMoon</dc:creator>
      <dc:date>2016-12-07T07:45:23Z</dc:date>
    </item>
    <item>
      <title>Re: Optimise the sas  sql query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimise-the-sas-sql-query/m-p/317252#M69433</link>
      <description>What is the bottleneck? Please post the complete fullstimer output from the log.</description>
      <pubDate>Wed, 07 Dec 2016 09:31:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimise-the-sas-sql-query/m-p/317252#M69433</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-12-07T09:31:12Z</dc:date>
    </item>
    <item>
      <title>Re: Optimise the sas  sql query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimise-the-sas-sql-query/m-p/319049#M69976</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;: Thank you for your answer.&lt;/P&gt;
&lt;P&gt;as I said before it is about 10 minutes&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2016 20:54:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimise-the-sas-sql-query/m-p/319049#M69976</guid>
      <dc:creator>LineMoon</dc:creator>
      <dc:date>2016-12-14T20:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: Optimise the sas  sql query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimise-the-sas-sql-query/m-p/319063#M69986</link>
      <description>&lt;P&gt;Feel free to not supply the information requested and not get the help you want.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2016 22:03:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimise-the-sas-sql-query/m-p/319063#M69986</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-12-14T22:03:56Z</dc:date>
    </item>
  </channel>
</rss>

