<?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 Performance in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546303#M151237</link>
    <description>&lt;P&gt;Tried hash and got this error - still searching for other options, but this suggests hash is not a viable solution in this case.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Hash object added 2097136 items when memory failure occurred.&lt;/P&gt;&lt;P&gt;FATAL: Insufficient memory to execute DATA step program. Aborted during the EXECUTION phase.&lt;/P&gt;&lt;P&gt;ERROR: The SAS System stopped processing this step because of insufficient memory.&lt;/P&gt;</description>
    <pubDate>Tue, 26 Mar 2019 20:35:19 GMT</pubDate>
    <dc:creator>shl007</dc:creator>
    <dc:date>2019-03-26T20:35:19Z</dc:date>
    <item>
      <title>Proc SQL Performance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546277#M151225</link>
      <description>&lt;P&gt;Hello - I have a dataset with over 126 million rows. I'm running a proc sql&amp;nbsp;on that table to join to&amp;nbsp;another table with far fewer rows. The proc sql never finishes, even with a composite index. Any ideas for trying to improve the performance? I also looked at the site below, and nothing else seemed to help. Thanks for any tips.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://support.sas.com/documentation/cdl/en/sqlproc/62086/HTML/default/viewer.htm#a001360977.htm" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/sqlproc/62086/HTML/default/viewer.htm#a001360977.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 19:32:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546277#M151225</guid>
      <dc:creator>shl007</dc:creator>
      <dc:date>2019-03-26T19:32:06Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Performance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546279#M151226</link>
      <description>&lt;P&gt;It would likely help to at least include the code for the SQL and indicate which is the larger data set. Also if any of the sets involved are from another DBMS such as Oracle or DB2 you should indicate that and possibly include the options used for the connection with the database (no password or user name but other options may be important).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And how long have you waited? Depending on the complexity of the query and the type of join a couple of hours may not be excessive.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 19:42:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546279#M151226</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-26T19:42:38Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Performance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546281#M151228</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you are sure that you are not generating cartesian product, maybe you can try an alternative like using arrays or hash objects.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings09/071-2009.pdf" target="_self"&gt;http://support.sas.com/resources/papers/proceedings09/071-2009.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Rajesh.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 19:46:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546281#M151228</guid>
      <dc:creator>Rajesh3</dc:creator>
      <dc:date>2019-03-26T19:46:04Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Performance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546283#M151229</link>
      <description>&lt;P&gt;Here is the SQL - "master_bkp" has the 126 million rows. Using proc datasets in a prior step, I had created a composite index on field1 and field2.&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;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;create&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;table&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;test &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select&lt;/FONT&gt; &lt;FONT color="#008080" face="Courier New" size="3"&gt;*&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;master_bkp a,&amp;nbsp;lookup b&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; b.field1 = a.field2 &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;and&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; a.field1 &amp;lt; b.field2&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 19:48:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546283#M151229</guid>
      <dc:creator>shl007</dc:creator>
      <dc:date>2019-03-26T19:48:46Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Performance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546290#M151232</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/216466"&gt;@shl007&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Here is the SQL - "master_bkp" has the 126 million rows. Using proc datasets in a prior step, I had created a composite index on field1 and field2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#000080"&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;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;create&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;table&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;test &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;as&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;select&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#008080"&gt;*&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;master_bkp a,&amp;nbsp;lookup b&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; b.field1 = a.field2 &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;and&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; a.field1 &amp;lt; b.field2&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Looks like a cross join instead of a right join.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;None of those tables appear to be on a server either, so is this work happening on a server or your computer? If it's on a desktop with 126 million rows, I'm not surprised it won't complete.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;

create table test as

select * from master_bkp as a

inner join lookup as b

on a.field2=b.field1 and a.field1 &amp;lt; b.field2;

quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Mar 2019 20:02:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546290#M151232</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-03-26T20:02:06Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Performance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546292#M151234</link>
      <description>&lt;P&gt;On the server, not on my desktop. Note: field1 &amp;amp; field2 are key fields in the "lookup" table. Wondering if a hash approach would help.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 20:04:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546292#M151234</guid>
      <dc:creator>shl007</dc:creator>
      <dc:date>2019-03-26T20:04:25Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Performance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546300#M151235</link>
      <description>&lt;P&gt;Did you try the modified query?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try it by limiting obs for 1,000,000 records with each set of code to see which is performing better.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hash would likely work, but not my strong suit, so you'll have to wait for someone else to help with that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/216466"&gt;@shl007&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;On the server, not on my desktop. Note: field1 &amp;amp; field2 are key fields in the "lookup" table. Wondering if a hash approach would help.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 20:23:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546300#M151235</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-03-26T20:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Performance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546303#M151237</link>
      <description>&lt;P&gt;Tried hash and got this error - still searching for other options, but this suggests hash is not a viable solution in this case.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Hash object added 2097136 items when memory failure occurred.&lt;/P&gt;&lt;P&gt;FATAL: Insufficient memory to execute DATA step program. Aborted during the EXECUTION phase.&lt;/P&gt;&lt;P&gt;ERROR: The SAS System stopped processing this step because of insufficient memory.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 20:35:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546303#M151237</guid>
      <dc:creator>shl007</dc:creator>
      <dc:date>2019-03-26T20:35:19Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Performance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546307#M151238</link>
      <description>&lt;P&gt;I'm not sure about this, but it might help to define your index on Field2, Field1 , in that order, on master_bkp and on Field1, Field2, in that order, on lookup, so that your equality join condition is the first index field in both tables.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 20:47:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546307#M151238</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-03-26T20:47:58Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Performance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546313#M151242</link>
      <description>&lt;P&gt;Are you using your lookup table as the hash object, not the master table? How many rows are in the lookup table?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 21:14:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546313#M151242</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-03-26T21:14:35Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Performance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546316#M151244</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first thing to do when this happens is add the &lt;FONT face="courier new,courier"&gt;_method&lt;/FONT&gt; option on &lt;FONT face="courier new,courier"&gt;proc sql&lt;/FONT&gt;, to see what joins are used.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can then decide on the next step, depending on your expectations vs the reality.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Indexes are probably not used, but you don't know at the moment (and maybe they shouldn't be used, depending on the size of the secondary table). You need to know what's happening -and monitor the effects of any change made- before proceeding, Otherwise you are just stabbing in the dark.&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, 26 Mar 2019 21:24:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546316#M151244</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-03-26T21:24:23Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Performance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546319#M151245</link>
      <description>&lt;P&gt;I'm using the master table as the one with the 126 million rows. Below is the hash code that generated that memory error. Again, running on server. Checking with server admin to see if increasing memsize would be a viable solution without adversely affecting anything. Other than that, at a loss ...&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;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; mastertest;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; _n_=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;declare&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; hash e(dataset: &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'master'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;e.definekey(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'key'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;e.definedata(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'datetime'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;, &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'detailid'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;, &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'datasetid'&lt;/FONT&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;e.definedone();&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; missing(datetime, detailid, datasetid);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;lookup (&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;obs&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;15&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;); &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;drop&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; rc;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;rc=e.find();&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; rc=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; key=catx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;' '&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,datetime, detailid, datasetid); &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;else&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; key=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'** Not Found'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 21:26:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546319#M151245</guid>
      <dc:creator>shl007</dc:creator>
      <dc:date>2019-03-26T21:26:03Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Performance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546320#M151246</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;Tried hash and got this error - still searching for other options, but this suggests hash is not a viable solution in this case.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe not. Several hash merges may well be faster than a single SQL join involving a large sort or overuse of indexes.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 21:28:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546320#M151246</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-03-26T21:28:04Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Performance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546321#M151247</link>
      <description>&lt;P&gt;You need to inverse the position of LOOKUP and MASTER in your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Read the MASTER table sequentially with statement SET, and load the LOOKUP table in the hash object.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 21:30:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546321#M151247</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-03-26T21:30:00Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Performance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546327#M151251</link>
      <description>&lt;P&gt;Hello -&amp;nbsp;I&amp;nbsp;assume&amp;nbsp;the _method option on proc sql&amp;nbsp;would require that the SQL actually finishes running? That is part of my issue ... Maybe I run it on a subset of the large dataset, but then is that modeling reality? Thanks for all the tips.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, on the response mentioning multiple hashes, what do you mean by multiple? Meaning multiple key fields?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 21:49:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546327#M151251</guid>
      <dc:creator>shl007</dc:creator>
      <dc:date>2019-03-26T21:49:46Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Performance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546331#M151255</link>
      <description>&lt;P&gt;&lt;EM&gt;I&amp;nbsp;assume&amp;nbsp;the _method option on proc sql&amp;nbsp;would require that the SQL actually finishes running?&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;The _method option does not require the query to complete. Look it up.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Also, on the response mentioning multiple hashes, what do you mean by multiple? Meaning multiple key fields?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;I mean several successive data steps where you only fetch part of the lookup data.&lt;/P&gt;
&lt;P&gt;This is in case your lookup data is too large to fit in memory: you look up one half (for example) and then the other half.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 22:30:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546331#M151255</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-03-26T22:30:31Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Performance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546336#M151259</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/216466"&gt;@shl007&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the lookup table fits into memory then the hash approach sounds promising to me.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you can't get things work then eventually provide some representative sample data (created via SAS data step code) for both your master and lookup table so we can start answering "in code".&lt;/P&gt;
&lt;P&gt;The closer the sample data reflects your real data (i.e. variable names and type) the closer the code posted will be to what you need in the end.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 22:45:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546336#M151259</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-03-26T22:45:44Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Performance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546379#M151282</link>
      <description>&lt;P&gt;If your LOOKUP dataset never has duplicates in its key (field1 renamed as _field1 below), then this may be quite simple.&amp;nbsp; Even if there are duplicates, there wouldn't be much change in the code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test (drop=_:);
  if _n_=1 then do;
    if 0 then set update (rename=(field1=_field1 field2=_field2));
    declare hash upd (dataset:'update (rename=(field1=_field1 field2=_field2))',hashexp:12);
      upd.definekey('_field1'); 
      upd.definedata(all:'Y');
      upd.definedone();
  end;
  set large;
  if upd.find(key:field2)=0 and field1&amp;lt;_field2;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I use "hashexp:12" to tell sas to use up to 4096 (=2**12) &amp;nbsp;"buckets" for hash object UPD.&amp;nbsp; The default is hashexp:8.&amp;nbsp; The maximum is hashexp:20.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I rename the variables field1 and field2 in data set update, because otherwise a successful find method would overwrite the values for field1 and field2 in the master dataset, which your sql code would not do.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 06:17:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546379#M151282</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-03-27T06:17:27Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Performance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546438#M151301</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P style="background-color: transparent; box-sizing: border-box; color: #333333; font-family: &amp;amp;quot; helevticaneue-light&amp;amp;quot;,&amp;amp;quot;helvetica neue&amp;amp;quot;,helvetica,arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 21.33px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px; padding: 0px; margin: 0px;"&gt;Here is the SQL - "master_bkp" has the 126 million rows. Using proc datasets in a prior step, I had created a composite index on field1 and field2.&lt;/P&gt;
&lt;P style="background-color: transparent; box-sizing: border-box; color: #333333; font-family: &amp;amp;quot; helevticaneue-light&amp;amp;quot;,&amp;amp;quot;helvetica neue&amp;amp;quot;,helvetica,arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 21.33px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="background-color: transparent; box-sizing: border-box; color: #333333; font-family: &amp;amp;quot; helevticaneue-light&amp;amp;quot;,&amp;amp;quot;helvetica neue&amp;amp;quot;,helvetica,arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 21.33px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px; padding: 0px; margin: 0px;"&gt;&lt;FONT color="#000080" face="Courier New" size="3" style="box-sizing: border-box; line-height: normal;"&gt;&lt;STRONG style="box-sizing: border-box; font-style: normal; font-weight: bold;"&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG style="box-sizing: border-box; font-style: normal; font-weight: bold;"&gt;&lt;FONT color="#000080" face="Courier New" size="3" style="box-sizing: border-box; line-height: normal;"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3" style="box-sizing: border-box; line-height: normal;"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="background-color: transparent; box-sizing: border-box; color: #333333; font-family: &amp;amp;quot; helevticaneue-light&amp;amp;quot;,&amp;amp;quot;helvetica neue&amp;amp;quot;,helvetica,arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 21.33px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px; padding: 0px; margin: 0px;"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3" style="box-sizing: border-box; line-height: normal;"&gt;create&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3" style="box-sizing: border-box; line-height: normal;"&gt;table&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" style="box-sizing: border-box; line-height: normal;"&gt;&amp;nbsp;test &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3" style="box-sizing: border-box; line-height: normal;"&gt;as&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="background-color: transparent; box-sizing: border-box; color: #333333; font-family: &amp;amp;quot; helevticaneue-light&amp;amp;quot;,&amp;amp;quot;helvetica neue&amp;amp;quot;,helvetica,arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 21.33px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px; padding: 0px; margin: 0px;"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3" style="box-sizing: border-box; line-height: normal;"&gt;select&lt;/FONT&gt; &lt;FONT color="#008080" face="Courier New" size="3" style="box-sizing: border-box; line-height: normal;"&gt;*&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="background-color: transparent; box-sizing: border-box; color: #333333; font-family: &amp;amp;quot; helevticaneue-light&amp;amp;quot;,&amp;amp;quot;helvetica neue&amp;amp;quot;,helvetica,arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 21.33px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px; padding: 0px; margin: 0px;"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3" style="box-sizing: border-box; line-height: normal;"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" style="box-sizing: border-box; line-height: normal;"&gt;&amp;nbsp;master_bkp a,&amp;nbsp;lookup b&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="background-color: transparent; box-sizing: border-box; color: #333333; font-family: &amp;amp;quot; helevticaneue-light&amp;amp;quot;,&amp;amp;quot;helvetica neue&amp;amp;quot;,helvetica,arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 21.33px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px; padding: 0px; margin: 0px;"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3" style="box-sizing: border-box; line-height: normal;"&gt;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" style="box-sizing: border-box; line-height: normal;"&gt; b.field1 = a.field2 &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3" style="box-sizing: border-box; line-height: normal;"&gt;and&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" style="box-sizing: border-box; line-height: normal;"&gt; a.field1 &amp;lt; b.field2&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="background-color: transparent; box-sizing: border-box; color: #333333; font-family: &amp;amp;quot; helevticaneue-light&amp;amp;quot;,&amp;amp;quot;helvetica neue&amp;amp;quot;,helvetica,arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 21.33px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px; padding: 0px; margin: 0px;"&gt;&lt;FONT face="Courier New" size="3" style="box-sizing: border-box; line-height: normal;"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="background-color: transparent; box-sizing: border-box; color: #333333; font-family: &amp;amp;quot; helevticaneue-light&amp;amp;quot;,&amp;amp;quot;helvetica neue&amp;amp;quot;,helvetica,arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 21.33px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px; padding: 0px; margin: 0px;"&gt;&lt;FONT color="#000080" face="Courier New" size="3" style="box-sizing: border-box; line-height: normal;"&gt;&lt;STRONG style="box-sizing: border-box; font-style: normal; font-weight: bold;"&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" style="box-sizing: border-box; line-height: normal;"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="background-color: transparent; box-sizing: border-box; color: #333333; font-family: &amp;amp;quot; helevticaneue-light&amp;amp;quot;,&amp;amp;quot;helvetica neue&amp;amp;quot;,helvetica,arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 21.33px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P style="background-color: transparent; box-sizing: border-box; color: #333333; font-family: &amp;amp;quot; helevticaneue-light&amp;amp;quot;,&amp;amp;quot;helvetica neue&amp;amp;quot;,helvetica,arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 21.33px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px; padding: 0px; margin: 0px;"&gt;&lt;FONT face="Courier New" size="3" style="box-sizing: border-box; line-height: normal;"&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #333333; cursor: text; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;Rather than using a composite index and SQL, I would go with a simple index on FIELD2 in master_bkp, and use a datastep, something like:&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="background-color: transparent; box-sizing: border-box; color: #333333; font-family: &amp;amp;quot; helevticaneue-light&amp;amp;quot;,&amp;amp;quot;helvetica neue&amp;amp;quot;,helvetica,arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 21.33px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px; padding: 0px; margin: 0px;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;FONT face="Courier New" size="3" style="box-sizing: border-box; line-height: normal;"&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create index field2 on master_bkp(field2);
quit;


data want;
  set lookup;
  lookup_field2=field2; /* save the value */
  do field2=.,field1; /* in case there are duplicates on lookup, refresh with a non-existing key */
    do until(0); /* do forever, or until LEAVE */
      set master_bkp(rename=(field1=master_field1)) key=field2;
      if _iorc_ then do; &lt;FONT face="Consolas"&gt;/* last row read, no more found */&lt;/FONT&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; _error_=0; /* when _iorc_ is set, _error_ is also set, but we do not want an error message&amp;nbsp;*/      
        leave;  
        end;
      if field1&amp;lt;lookup_field2 then
        output;
      end;
    end;
run; &lt;/CODE&gt;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2" style="box-sizing: border-box; line-height: normal;"&gt;I am not sure SAS is that good at using composite indexes for non-identical queries (like your comparison using "&amp;lt;"), but this is probably going to work (not tested, though, no test data). You can try it out with a single obs from lookup first, to check the syntax, and see how it performs.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2019 10:55:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546438#M151301</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2019-03-27T10:55:26Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL Performance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546609#M151359</link>
      <description>Adding&lt;BR /&gt;Options msglevel=i;&lt;BR /&gt;will let th know if the indexed is being used.&lt;BR /&gt;Also adding&lt;BR /&gt;PROC SQL _method;&lt;BR /&gt;will let you know what query strategy is being used.</description>
      <pubDate>Wed, 27 Mar 2019 17:26:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Performance/m-p/546609#M151359</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2019-03-27T17:26:32Z</dc:date>
    </item>
  </channel>
</rss>

