<?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 Passing a list of values to Oracle in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-list-of-values-to-Oracle/m-p/363897#M86226</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; I am having a problem with passing a list of values, currently in a SAS dataset, to Oracle in an IN clause. &amp;nbsp;While doing that with a SELECT in the IN the code runs but it never finishes. &amp;nbsp;I have tried using a join instead with "multi_datasrc_opt = IN_CLAUSE" that works until I join a third table (I have about 7 to join), then it never returns as well. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; I was hoping there is a SAS equivalent of Oracles EXECUTE IMMEDIATE where I could pass through a query in a string to Oracle directly, but so far I haven't found it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Sorry if this is a newbie question, but I've been hitting my head against a wall for 2 weeks trying to figure it out..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;BR /&gt;Paul.&lt;/P&gt;</description>
    <pubDate>Fri, 02 Jun 2017 18:06:42 GMT</pubDate>
    <dc:creator>vtguy22</dc:creator>
    <dc:date>2017-06-02T18:06:42Z</dc:date>
    <item>
      <title>Passing a list of values to Oracle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-list-of-values-to-Oracle/m-p/363897#M86226</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; I am having a problem with passing a list of values, currently in a SAS dataset, to Oracle in an IN clause. &amp;nbsp;While doing that with a SELECT in the IN the code runs but it never finishes. &amp;nbsp;I have tried using a join instead with "multi_datasrc_opt = IN_CLAUSE" that works until I join a third table (I have about 7 to join), then it never returns as well. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; I was hoping there is a SAS equivalent of Oracles EXECUTE IMMEDIATE where I could pass through a query in a string to Oracle directly, but so far I haven't found it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Sorry if this is a newbie question, but I've been hitting my head against a wall for 2 weeks trying to figure it out..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;BR /&gt;Paul.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2017 18:06:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-a-list-of-values-to-Oracle/m-p/363897#M86226</guid>
      <dc:creator>vtguy22</dc:creator>
      <dc:date>2017-06-02T18:06:42Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a list of values to Oracle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-list-of-values-to-Oracle/m-p/363907#M86231</link>
      <description>&lt;P&gt;Could you post some sample code/data? &amp;nbsp;Are you using explicit or implicit pass-through SQL or using it through a LIBNAME connection on DATA steps? &amp;nbsp;There are a lot of odd things I've run across on the interface between Oracle and SAS, but I'd need more info to help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In general I've found with most DB's it's best to push the data to all one location, either do everything in the DB using explicit pass-through or pull everything into SAS and work with it in datasets, but there are always exceptions to this as well.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2017 18:41:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-a-list-of-values-to-Oracle/m-p/363907#M86231</guid>
      <dc:creator>Sven111</dc:creator>
      <dc:date>2017-06-02T18:41:20Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a list of values to Oracle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-list-of-values-to-Oracle/m-p/363921#M86237</link>
      <description>&lt;P&gt;You might post example code starting with connection to see if any of the Oracle users will recognize a problem.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2017 19:50:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-a-list-of-values-to-Oracle/m-p/363921#M86237</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-06-02T19:50:19Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a list of values to Oracle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-list-of-values-to-Oracle/m-p/364238#M86361</link>
      <description>&lt;P&gt;Here's one of the variations I've tried. &amp;nbsp;I've also tried a passthrough, as well as joining to my_sas_table instead of using an IN. &amp;nbsp;The sas table is just for testing, in the real program that will by dynamically built from a prompt.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;LIBNAME mylib ORACLE PATH=mypath SCHEMA=myschema AUTHDOMAIN="mydomain" multi_datasrc_opt = IN_CLAUSE;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%global save_myvariable;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA my_sas_table;&lt;BR /&gt;INPUT receipt_number $13;&lt;BR /&gt;DATALINES;&lt;BR /&gt;ABC1700150001&lt;BR /&gt;ABC1700150001&lt;BR /&gt;ABC1700150001&lt;BR /&gt;ABC1700150001&lt;BR /&gt;ABC1700150001&lt;BR /&gt;ABC1700150001&lt;BR /&gt;ABC1700150001&lt;BR /&gt;ABC1700150001&lt;BR /&gt;ABC1700150001&lt;BR /&gt;ABC1700150001&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CREATE TABLE work.temp2 as&lt;BR /&gt;SELECT DISTINCT&lt;BR /&gt;t1.FILE_CODE,&lt;BR /&gt;t2.MAIN_FILE,&lt;BR /&gt;t3.LAST_ACTION&lt;BR /&gt;FROM&lt;BR /&gt;mylib.FILE_TABLE t1&lt;BR /&gt;LEFT JOIN mylib.FILE_TABLE t2 ON t1.FILE_ID = t2.MAIN_FILE_ID&lt;BR /&gt;LEFT JOIN mylib.FILE_DATES t3 ON t2.MAIN_FILE_ID=t3.FILE_ID AND t2.LAST_TRANSACTION_DATE=t3.TRANSACTION_DATE&lt;BR /&gt;WHERE&lt;BR /&gt;t1.FILE_CODE in (SELECT receipt_number FROM my_sas_table)&lt;BR /&gt;ORDER BY&lt;BR /&gt;t1.FILE_CODE;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;PROC Print data=work.temp2;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jun 2017 10:47:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-a-list-of-values-to-Oracle/m-p/364238#M86361</guid>
      <dc:creator>vtguy22</dc:creator>
      <dc:date>2017-06-05T10:47:36Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a list of values to Oracle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-list-of-values-to-Oracle/m-p/364258#M86375</link>
      <description>Figured it out. I broke all of my joins into unique CREATE TABLEs. Not elegant, but it works and is fast..</description>
      <pubDate>Mon, 05 Jun 2017 12:36:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-a-list-of-values-to-Oracle/m-p/364258#M86375</guid>
      <dc:creator>vtguy22</dc:creator>
      <dc:date>2017-06-05T12:36:04Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a list of values to Oracle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-list-of-values-to-Oracle/m-p/364479#M86452</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/147000"&gt;@vtguy22&lt;/a&gt;: There is another way to get stuff into an IN clause in Oracle - put the unique values (in single quotes) in a macro variable:&lt;/P&gt;&lt;PRE&gt;Proc sql;
  select distinct cats("'",tranwrd(receipt_number,"'","''"),"'") into :receipts separated by ','
  from my_sas_table;
quit;
  &lt;/PRE&gt;&lt;P&gt;The TRANWRD() doubles single quotes already in the variable, so that they get quoted correctly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You should now be able to do your Oracle query as passthrough, using&lt;/P&gt;&lt;PRE&gt;where t1.FILE_CODE in(&amp;amp;receipts)&lt;/PRE&gt;&lt;P&gt;instead of referencing the SAS table which causes SAS to issue dynamic WHERE clauses, which is very inefficient.&lt;/P&gt;&lt;P&gt;There is a limit to how much you can squeeze into a WHERE clause this way, I think the current limit is 1000 items in an Oracle IN clause, and the limit for the length of SAS macro variables is 64K. But as long as you are within those limits, you should be fine.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2017 06:45:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-a-list-of-values-to-Oracle/m-p/364479#M86452</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2017-06-06T06:45:40Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a list of values to Oracle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-list-of-values-to-Oracle/m-p/364512#M86462</link>
      <description>&lt;P&gt;Thank you so much, that is beautiful!&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2017 10:33:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-a-list-of-values-to-Oracle/m-p/364512#M86462</guid>
      <dc:creator>vtguy22</dc:creator>
      <dc:date>2017-06-06T10:33:33Z</dc:date>
    </item>
  </channel>
</rss>

