<?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: proc sql using or in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-or/m-p/896459#M82962</link>
    <description>&lt;P&gt;Assuming you meant something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where (condition1)
   or (condition2)
   or (condition3)
....&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then the issue is probably related to the size of the data and whether or not indexes can be used.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you just have a simple condition involving equality test and AND operators then the indexes can be used to only join the observations that meet the criteria.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you start adding in OR conditions that is impossible for the SQL execution plan to take into account so it is probably reverting to doing full table scans for both input tables.&amp;nbsp; Which can result in a hugh intermediate file that might require a lot of DISK I/O to create and re-read.&lt;/P&gt;</description>
    <pubDate>Fri, 29 Sep 2023 15:19:06 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-09-29T15:19:06Z</dc:date>
    <item>
      <title>proc sql using or</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-or/m-p/896451#M82961</link>
      <description>&lt;P&gt;I have some legacy code that takes a very long time to run, on join is &amp;gt; 8 hours.&amp;nbsp; When I break it down it has many or and multiple filters:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;create table have as&lt;/P&gt;
&lt;P&gt;select a.*,b.*&lt;/P&gt;
&lt;P&gt;from table 1 a,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;table 2 b&lt;/P&gt;
&lt;P&gt;where a.id = b.id&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; and blah&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; or where a.id = b.id&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; and blah blah blah&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've broken this apart into 6 different queries.&amp;nbsp; I concatenate at the end in a dataset and it runs so much faster I'm shocked.&amp;nbsp; From hours to minutes.&amp;nbsp; I can't find much on using or like this other than it's not efficient.&amp;nbsp; Is there any rules/laws/best practices/documentation somewhere that details this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd like to have more than my test to take back to the original developers to get them to change their ways.&amp;nbsp; Thank You in advance&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2023 15:00:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-or/m-p/896451#M82961</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2023-09-29T15:00:06Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql using or</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-or/m-p/896459#M82962</link>
      <description>&lt;P&gt;Assuming you meant something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where (condition1)
   or (condition2)
   or (condition3)
....&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then the issue is probably related to the size of the data and whether or not indexes can be used.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you just have a simple condition involving equality test and AND operators then the indexes can be used to only join the observations that meet the criteria.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you start adding in OR conditions that is impossible for the SQL execution plan to take into account so it is probably reverting to doing full table scans for both input tables.&amp;nbsp; Which can result in a hugh intermediate file that might require a lot of DISK I/O to create and re-read.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2023 15:19:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-or/m-p/896459#M82962</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-29T15:19:06Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql using or</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-or/m-p/897396#M82972</link>
      <description>Principally speaking though, proc sql is multi-threaded, so you can also ramp up your processors.  SAS uses 4 by default, but if your computer/server is faster, you can increase it.  However, not all SAS procs are multi-threaded, just SQL happens to be one.</description>
      <pubDate>Thu, 05 Oct 2023 13:33:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-using-or/m-p/897396#M82972</guid>
      <dc:creator>awesome_opossum</dc:creator>
      <dc:date>2023-10-05T13:33:43Z</dc:date>
    </item>
  </channel>
</rss>

