<?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: Optimize SAS Code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Optimize-SAS-Code/m-p/532716#M145990</link>
    <description>&lt;P&gt;SAS does not use indexes when a OR operator is present (unless the table is accessed through the SPDE engine).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is your table indexed?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could try 2 queries linked by the UNION operator instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And you could turn on&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;option msglevel=i;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to see if indexes are used.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 04 Feb 2019 20:23:51 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2019-02-04T20:23:51Z</dc:date>
    <item>
      <title>Optimize SAS Code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimize-SAS-Code/m-p/532655#M145973</link>
      <description>&lt;P&gt;Hello.&amp;nbsp; I am trying to optimize by SAS code below.&amp;nbsp; The code highlighted in red is causing the query to run (&amp;gt; 1 hr).&amp;nbsp;&amp;nbsp; Before adding the "OR" statement, the query tool about a few minutes to run.&amp;nbsp; Please advise the best way to re-write this query to decrease the run time.&amp;nbsp; Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;create table meta_new as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;select distinct m.*, scan(m.ChartName, -&lt;STRONG&gt;2&lt;/STRONG&gt;, '._') as ProvID, left(m.ChartName,&lt;STRONG&gt;3&lt;/STRONG&gt;) as Vendor_ChartName&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from meta_data m&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; order by m.ChartName;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table merged_data_hicn as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;select distinct m.ChartName&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; from meta_new m, CDF c&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&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;&amp;nbsp;where m.MemberID = c.DBHICN&lt;/P&gt;&lt;P&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;&amp;nbsp;&amp;nbsp; &lt;FONT color="#ff0000"&gt;and (m.vendorid = &lt;STRONG&gt;20&lt;/STRONG&gt;) or (m.vendorid = &lt;STRONG&gt;9&lt;/STRONG&gt; and Vendor_ChartName = 'ABC')&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; and m.Provid = c.ProviderIDtxt&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;order by m.ChartName;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 18:07:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimize-SAS-Code/m-p/532655#M145973</guid>
      <dc:creator>adhikra</dc:creator>
      <dc:date>2019-02-04T18:07:04Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize SAS Code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimize-SAS-Code/m-p/532658#M145974</link>
      <description>&lt;P&gt;So its just the second query that needs rewriting, correct? How big are the two input data sets?&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 18:11:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimize-SAS-Code/m-p/532658#M145974</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-02-04T18:11:56Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize SAS Code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimize-SAS-Code/m-p/532670#M145975</link>
      <description>&lt;P&gt;Yes I need some help with the 2nd query.&amp;nbsp; The first dataset meta_new is about 2 million rows.&amp;nbsp; The 2nd dataset CDF is about 362,000 rows.&amp;nbsp; Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 18:25:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimize-SAS-Code/m-p/532670#M145975</guid>
      <dc:creator>adhikra</dc:creator>
      <dc:date>2019-02-04T18:25:02Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize SAS Code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimize-SAS-Code/m-p/532687#M145976</link>
      <description>&lt;P&gt;Are you getting the right result set from your second query? You may need to add extra brackets to get your OR condition working correctly:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;and ((m.vendorid = 20) or (m.vendorid = 9 and Vendor_ChartName = 'ABC'))&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Feb 2019 19:33:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimize-SAS-Code/m-p/532687#M145976</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-02-04T19:33:16Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize SAS Code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimize-SAS-Code/m-p/532690#M145977</link>
      <description>&lt;P&gt;It's difficult to rewrite your code without knowing your data. Can you provide a sample of your data to work with?&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 19:36:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimize-SAS-Code/m-p/532690#M145977</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-02-04T19:36:06Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize SAS Code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimize-SAS-Code/m-p/532709#M145984</link>
      <description>&lt;P&gt;I have attached the sample cdf file for your review.&amp;nbsp; Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 20:12:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimize-SAS-Code/m-p/532709#M145984</guid>
      <dc:creator>adhikra</dc:creator>
      <dc:date>2019-02-04T20:12:22Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize SAS Code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimize-SAS-Code/m-p/532711#M145985</link>
      <description>&lt;P&gt;Here is the sample meta_new for you to review&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 20:14:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimize-SAS-Code/m-p/532711#M145985</guid>
      <dc:creator>adhikra</dc:creator>
      <dc:date>2019-02-04T20:14:29Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize SAS Code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimize-SAS-Code/m-p/532716#M145990</link>
      <description>&lt;P&gt;SAS does not use indexes when a OR operator is present (unless the table is accessed through the SPDE engine).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is your table indexed?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could try 2 queries linked by the UNION operator instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And you could turn on&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;option msglevel=i;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to see if indexes are used.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 20:23:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimize-SAS-Code/m-p/532716#M145990</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-02-04T20:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize SAS Code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimize-SAS-Code/m-p/532759#M146000</link>
      <description>&lt;P&gt;For example:&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data CLASS(index=(AGE)); 
  set SASHELP.CLASS;
run;
option msglevel=i; 
proc sql; 
  create table T as 
  select * from CLASS 
  where AGE in(11,12);

  create table T as 
  select * from CLASS 
  where AGE=12 or (AGE=11 &amp;amp; NAME='Alice');
 
  create table T as 
  select * from CLASS where AGE=12
  union
  select * from CLASS where AGE=11 &amp;amp; NAME='Alice';
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;32 create table T as&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;33 select * from CLASS&lt;/FONT&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;34 where AGE in(11,12);&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;&lt;FONT face="courier new,courier"&gt;INFO: Index Age selected for WHERE clause optimization.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;NOTE: Compressing data set WORK.T increased size by 33.33 percent. &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Compressed is 4 pages; un-compressed would require 3 pages.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;35 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;36 create table T as&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;37 select * from CLASS&lt;/FONT&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;38 where AGE=12 or (AGE=11 &amp;amp; NAME='Alice');&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;NOTE: Compressing data set WORK.T increased size by 50.00 percent. &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Compressed is 3 pages; un-compressed would require 2 pages.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;39 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;40 create table T as&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;41 select * from CLASS where AGE=12&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;42 union&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;43 select * from CLASS where AGE=11 &amp;amp; NAME='Alice';&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;INFO: Index Age selected for WHERE clause optimization.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;INFO: Index Age selected for WHERE clause optimization.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;NOTE: Compressing data set WORK.T increased size by 50.00 percent. &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Compressed is 3 pages; un-compressed would require 2 pages.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 21:33:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimize-SAS-Code/m-p/532759#M146000</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-02-04T21:33:05Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize SAS Code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimize-SAS-Code/m-p/532792#M146020</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/257720"&gt;@adhikra&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have you already revisited your WHERE condition to verify if there aren't some brackets missing as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&amp;nbsp;suggests?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Executing the query with the added brackets would highly likely improve performance significantly.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 22:21:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimize-SAS-Code/m-p/532792#M146020</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-02-04T22:21:20Z</dc:date>
    </item>
    <item>
      <title>Re: Optimize SAS Code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Optimize-SAS-Code/m-p/532994#M146092</link>
      <description>&lt;P&gt;Thank you very much for your response.&amp;nbsp; Your answer did work and&amp;nbsp;I will mark it as a solution.&amp;nbsp; Thank you everyone for your help.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Feb 2019 16:28:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Optimize-SAS-Code/m-p/532994#M146092</guid>
      <dc:creator>adhikra</dc:creator>
      <dc:date>2019-02-05T16:28:28Z</dc:date>
    </item>
  </channel>
</rss>

