<?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: Approach for retrieving values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Approach-for-retrieving-values/m-p/344295#M272969</link>
    <description>&lt;P&gt;As far as I know you've got basically two options if you want to influence how and where heterogenous joins are executed.&lt;/P&gt;
&lt;P&gt;1. You load your smaller table into the DB with the larger table. You can use a temporary table for this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;A href="https://support.sas.com/documentation/cdl/en/acreldb/69580/HTML/default/viewer.htm#n0irpkyp22l7vzn1il9lx6f4wmx9.htm" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/acreldb/69580/HTML/default/viewer.htm#n0irpkyp22l7vzn1il9lx6f4wmx9.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;2. You pack the key values of the smaller tables into a where clause for a SQL sent to the DB with the larger table. That's what you're currently doing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In a company I've worked many years ago we've actually implemented a "sqlpump" macro which did exactly what you're doing now: Pack the keys into a macro variable and then send the SQL to the DB for execution; and we've implemented in a way that this executed&amp;nbsp;in multiple iterations when there were too many key values and then appended the result back in SAS.&lt;/P&gt;
&lt;P&gt;BTW: I believe some DBMS have a restriction of 32KB for SQL's so you want to limit your macro variable to something a bit lower than 32KB per call.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe that there is now a SAS dataset option DBMASTER which triggers SAS/Access to generate such code when using implicit SQL.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/documentation/cdl/en/acreldb/69580/HTML/default/viewer.htm#n0jg0sozl17mjyn1woelrrr76266.htm" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/acreldb/69580/HTML/default/viewer.htm#n0jg0sozl17mjyn1woelrrr76266.htm&amp;nbsp;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When using implicit SQL (so not pass-through) then also use the following options:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;options&lt;/EM&gt;&lt;SPAN&gt; sastrace=',,,d' sastraceloc=saslog &lt;/SPAN&gt;&lt;EM&gt;nostsuffix&lt;/EM&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This will show you in the log what SQL the SAS/Access engine actually sends to the database for execution.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 25 Mar 2017 13:25:46 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2017-03-25T13:25:46Z</dc:date>
    <item>
      <title>Approach for retrieving values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Approach-for-retrieving-values/m-p/344118#M272967</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently I am retrieving values from a database using macro variable as i have to do look up for the account values .i am doing below approach as it makes processing faster.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL NOPRINT;&lt;BR /&gt;Select Account_Num into :Accnt Separated by ','&lt;BR /&gt;from Anlsys;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;connect to odbc(dsn=mart);&lt;BR /&gt;create table Lookup as&lt;BR /&gt;select * from connection to odbc(select a.Account_Number,c.Score&amp;nbsp;&lt;BR /&gt;from mart.dbo.accounts a left join mart.dbo.ACCOUNT_FACTS b&lt;BR /&gt;on ( a.actkey = b.actkey)&lt;BR /&gt;left join mart.dbo.Score_yr c&lt;BR /&gt;on(b.FKey =c.FKey)&lt;BR /&gt;where a.Account_Number IN (&amp;amp;Accnt)&lt;BR /&gt;);&lt;BR /&gt;disconnect from odbc;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't have any checks on macro variable length.I am exposing to risk of exceeding macro variable length but i know the accounts list might not be that much but still little concern&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any other better approach to retrieve efficiently instead of pulling the whole table into sas&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 16:22:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Approach-for-retrieving-values/m-p/344118#M272967</guid>
      <dc:creator>JasonNC</dc:creator>
      <dc:date>2017-03-24T16:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: Approach for retrieving values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Approach-for-retrieving-values/m-p/344227#M272968</link>
      <description>The macro variable will hold 64K characters, so depending on the length of your account number (+1 for the comma) you can get a good approximation of how many will fit.&lt;BR /&gt;&lt;BR /&gt;if you can push the WORK.ANLSYS up to the data base you can add it to your join to do the elimination.</description>
      <pubDate>Sat, 25 Mar 2017 00:25:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Approach-for-retrieving-values/m-p/344227#M272968</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2017-03-25T00:25:56Z</dc:date>
    </item>
    <item>
      <title>Re: Approach for retrieving values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Approach-for-retrieving-values/m-p/344295#M272969</link>
      <description>&lt;P&gt;As far as I know you've got basically two options if you want to influence how and where heterogenous joins are executed.&lt;/P&gt;
&lt;P&gt;1. You load your smaller table into the DB with the larger table. You can use a temporary table for this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;A href="https://support.sas.com/documentation/cdl/en/acreldb/69580/HTML/default/viewer.htm#n0irpkyp22l7vzn1il9lx6f4wmx9.htm" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/acreldb/69580/HTML/default/viewer.htm#n0irpkyp22l7vzn1il9lx6f4wmx9.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;2. You pack the key values of the smaller tables into a where clause for a SQL sent to the DB with the larger table. That's what you're currently doing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In a company I've worked many years ago we've actually implemented a "sqlpump" macro which did exactly what you're doing now: Pack the keys into a macro variable and then send the SQL to the DB for execution; and we've implemented in a way that this executed&amp;nbsp;in multiple iterations when there were too many key values and then appended the result back in SAS.&lt;/P&gt;
&lt;P&gt;BTW: I believe some DBMS have a restriction of 32KB for SQL's so you want to limit your macro variable to something a bit lower than 32KB per call.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe that there is now a SAS dataset option DBMASTER which triggers SAS/Access to generate such code when using implicit SQL.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/documentation/cdl/en/acreldb/69580/HTML/default/viewer.htm#n0jg0sozl17mjyn1woelrrr76266.htm" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/acreldb/69580/HTML/default/viewer.htm#n0jg0sozl17mjyn1woelrrr76266.htm&amp;nbsp;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When using implicit SQL (so not pass-through) then also use the following options:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;options&lt;/EM&gt;&lt;SPAN&gt; sastrace=',,,d' sastraceloc=saslog &lt;/SPAN&gt;&lt;EM&gt;nostsuffix&lt;/EM&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This will show you in the log what SQL the SAS/Access engine actually sends to the database for execution.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Mar 2017 13:25:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Approach-for-retrieving-values/m-p/344295#M272969</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-03-25T13:25:46Z</dc:date>
    </item>
  </channel>
</rss>

