<?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: How to get a small set of records from a very large table in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-get-a-small-set-of-records-from-a-very-large-table/m-p/203665#M50795</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is in your libname pointing to the SQL Server option "MULTI_DATASRC_OPT=IN_CLAUSE" defined?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Use below option in your code to see in the SAS log what code actually gets sent to the dbms&lt;/P&gt;&lt;P&gt;OPTIONS SASTRACE=',,,d' SASTRACELOC=SASLOG NOSTSUFFIX;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is the code executed for 1000 and 2000 obs at a time the same? Just thinking that may-be you're exceeding with 2000 id's some threshold where SAS needs to generate different SQL code.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 18 Mar 2015 15:11:48 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2015-03-18T15:11:48Z</dc:date>
    <item>
      <title>How to get a small set of records from a very large table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-get-a-small-set-of-records-from-a-very-large-table/m-p/203660#M50790</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a list of of about 20,000 ids (length $20.). There is a SQL Server database table on a server somewhere with about 2 billion records. I need to get all the records from that table for my list of ids. I work on a 64-bit PC and connect to the database with an OLEDB libname A. I tried the following code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt; create table NEW as select * from id_list i, A.bigTable t where i.id = t.id;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This took forever to run and failed because my server connection timed out at 8 hours. So I added a variable to id_list (obsnum=_n_;) and modified the syntax to:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; create table NEW as select * from id_list (where=(1 le obsnum le 1000)) i, A.bigTable t where i.id = t.id;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This took 12 seconds (real time) to run. So I wrote a macro to do this and ran it 20 times, giving it a new thousand-id range each time.&lt;/P&gt;&lt;P&gt;Then I thought, why not try 2000 ids at a time, instead of 1000. 30 minutes later, this query was not complete so I stopped it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My question is: what accounts for the huge increase in time when I try to get records for more than 1000 ids at a time? Is there a better method to go against a very large table to find records?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Mar 2015 17:37:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-get-a-small-set-of-records-from-a-very-large-table/m-p/203660#M50790</guid>
      <dc:creator>Karen</dc:creator>
      <dc:date>2015-03-17T17:37:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a small set of records from a very large table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-get-a-small-set-of-records-from-a-very-large-table/m-p/203661#M50791</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How you connect may be an issue but one of the first things is only select the variables you need.&lt;/P&gt;&lt;P&gt;The selection may be quicker as pass-through as well.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Mar 2015 17:40:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-get-a-small-set-of-records-from-a-very-large-table/m-p/203661#M50791</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-03-17T17:40:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a small set of records from a very large table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-get-a-small-set-of-records-from-a-very-large-table/m-p/203662#M50792</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is it possible that you have missing IDs after first 1000 IDs? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Mar 2015 17:51:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-get-a-small-set-of-records-from-a-very-large-table/m-p/203662#M50792</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2015-03-17T17:51:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a small set of records from a very large table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-get-a-small-set-of-records-from-a-very-large-table/m-p/203663#M50793</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you create a table in the SQL database to store the list?&lt;/P&gt;&lt;P&gt;Otherwise you might be better off using the SAS dataset to generate WHERE clauses against the large table.&lt;/P&gt;&lt;P&gt;Here is an example. You might have to adjust if your ID variable is character or if it is too long to fit 1000 values into a single macro variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;proc sql noprint ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; select distinct id into :idlist1 separated by ',' from &lt;SPAN style="background-color: #ffffff;"&gt;id_list (firstobs=1 obs=1000) ;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; select distinct id into :idlist2 separated by ',' from &lt;SPAN style="background-color: #ffffff;"&gt;id_list (firstobs=1001 obs=2000) ;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff; font-family: 'courier new', courier; font-size: 10pt; line-height: 1.5em;"&gt;&amp;nbsp; create table NEW as select * from A.BIGTABLE&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;&amp;nbsp; where id in (&amp;amp;idlist1,&amp;amp;idlist2)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Mar 2015 18:00:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-get-a-small-set-of-records-from-a-very-large-table/m-p/203663#M50793</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-03-17T18:00:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a small set of records from a very large table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-get-a-small-set-of-records-from-a-very-large-table/m-p/203664#M50794</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You'd better create a INDEX for that prime key variable for a large table .and try to use PASS-Through SQL ,let SQL Server to do such heavy work.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Mar 2015 13:47:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-get-a-small-set-of-records-from-a-very-large-table/m-p/203664#M50794</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2015-03-18T13:47:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a small set of records from a very large table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-get-a-small-set-of-records-from-a-very-large-table/m-p/203665#M50795</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is in your libname pointing to the SQL Server option "MULTI_DATASRC_OPT=IN_CLAUSE" defined?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Use below option in your code to see in the SAS log what code actually gets sent to the dbms&lt;/P&gt;&lt;P&gt;OPTIONS SASTRACE=',,,d' SASTRACELOC=SASLOG NOSTSUFFIX;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is the code executed for 1000 and 2000 obs at a time the same? Just thinking that may-be you're exceeding with 2000 id's some threshold where SAS needs to generate different SQL code.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Mar 2015 15:11:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-get-a-small-set-of-records-from-a-very-large-table/m-p/203665#M50795</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-03-18T15:11:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a small set of records from a very large table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-get-a-small-set-of-records-from-a-very-large-table/m-p/203666#M50796</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My guess is that you are moving the whole source table to SAS for the join.&lt;/P&gt;&lt;P&gt;Try the DBKEY= ds option for the cross platform join.&lt;/P&gt;&lt;P&gt;If that doesn't work for you, consider to use a temporary table in SQLS so you are sure that the whole join will take place where the data is.&lt;/P&gt;&lt;P&gt;As &lt;A __default_attr="645292" __jive_macro_name="user" class="jive_macro jive_macro_user" data-objecttype="3" href="https://communities.sas.com/"&gt;&lt;/A&gt; said, be sure that the id column is indexed.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Mar 2015 15:25:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-get-a-small-set-of-records-from-a-very-large-table/m-p/203666#M50796</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2015-03-18T15:25:54Z</dc:date>
    </item>
  </channel>
</rss>

