<?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: Passing parameters to SQL query in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Passing-parameters-to-SQL-query/m-p/75658#M21955</link>
    <description>How about&lt;BR /&gt;
&lt;BR /&gt;
&lt;U&gt;sas sql:&lt;/U&gt;&lt;BR /&gt;
select unique EMPNO into :EMPNOS separated by ',' from EMPLIST;&lt;BR /&gt;
&lt;BR /&gt;
&lt;U&gt;db2 passthough sql:&lt;/U&gt;&lt;BR /&gt;
Select emp_name, emp_status from EMPLOYEE&lt;BR /&gt;
WHERE Employee_NO in (&amp;amp;EMPNOS) ; &lt;BR /&gt;
&lt;BR /&gt;
Limitation: &amp;amp;EMPNOS is limited to 64k ... but you can always use several lists if db2 supports longer sql statements.</description>
    <pubDate>Wed, 14 Oct 2009 20:54:57 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2009-10-14T20:54:57Z</dc:date>
    <item>
      <title>Passing parameters to SQL query</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Passing-parameters-to-SQL-query/m-p/75656#M21953</link>
      <description>I have a SQL query which needs parameters in where clause. I need to pass parameters from sas data set. Can I do this with "PROC DB2EXT IN=EMPLIST" where EMPLIST is sas dataset. &lt;BR /&gt;
Ex: I have to read employee details from the db2 table for all the EMPNO in sas data set. Can someone advice me if I can do this with PROC DB2EXT? My query looks like this:&lt;BR /&gt;
Select emp_name, emp_status from EMPLOYEE&lt;BR /&gt;
WHERE Employee_NO  = '%(&amp;amp;EMPLIST.EMPNO)' ;  &lt;BR /&gt;
&lt;BR /&gt;
I am executing SAS on OS/390 mainframe.</description>
      <pubDate>Wed, 14 Oct 2009 13:56:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Passing-parameters-to-SQL-query/m-p/75656#M21953</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-10-14T13:56:24Z</dc:date>
    </item>
    <item>
      <title>Re: Passing parameters to SQL query</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Passing-parameters-to-SQL-query/m-p/75657#M21954</link>
      <description>When I need to select accounts from a large DB2 table, I pass the account numbers that I have in a sas dataset using a proc format.  I make sure I have one records per account, so I sort the data using the nodupkey option, then setup the sql like below.&lt;BR /&gt;
&lt;BR /&gt;
other sas code that reads the accounts ...&lt;BR /&gt;
PROC SORT DATA=ACCOUNTS OUT=NUM(KEEP=NUMBER) NODUPKEY;&lt;BR /&gt;
  BY NUMBER;&lt;BR /&gt;
&lt;BR /&gt;
DATA TEMP (KEEP = FMTNAME TYPE LABEL START);&lt;BR /&gt;
  SET NUM;&lt;BR /&gt;
&lt;BR /&gt;
START   = NUMBER;&lt;BR /&gt;
FMTNAME = 'ACCTF';&lt;BR /&gt;
TYPE    = 'N';&lt;BR /&gt;
LABEL   = 'KEEPME';&lt;BR /&gt;
&lt;BR /&gt;
PROC FORMAT CNTLIN=TEMP;&lt;BR /&gt;
&lt;BR /&gt;
PROC SQL;&lt;BR /&gt;
SELECT *&lt;BR /&gt;
FROM EMPLOYEE&lt;BR /&gt;
WHERE PUT(NUMBER,ACCTF.) = 'KEEPME';&lt;BR /&gt;
&lt;BR /&gt;
This selects only the account numbers that were included in the original dataset.</description>
      <pubDate>Wed, 14 Oct 2009 16:17:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Passing-parameters-to-SQL-query/m-p/75657#M21954</guid>
      <dc:creator>garybald</dc:creator>
      <dc:date>2009-10-14T16:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: Passing parameters to SQL query</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Passing-parameters-to-SQL-query/m-p/75658#M21955</link>
      <description>How about&lt;BR /&gt;
&lt;BR /&gt;
&lt;U&gt;sas sql:&lt;/U&gt;&lt;BR /&gt;
select unique EMPNO into :EMPNOS separated by ',' from EMPLIST;&lt;BR /&gt;
&lt;BR /&gt;
&lt;U&gt;db2 passthough sql:&lt;/U&gt;&lt;BR /&gt;
Select emp_name, emp_status from EMPLOYEE&lt;BR /&gt;
WHERE Employee_NO in (&amp;amp;EMPNOS) ; &lt;BR /&gt;
&lt;BR /&gt;
Limitation: &amp;amp;EMPNOS is limited to 64k ... but you can always use several lists if db2 supports longer sql statements.</description>
      <pubDate>Wed, 14 Oct 2009 20:54:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Passing-parameters-to-SQL-query/m-p/75658#M21955</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2009-10-14T20:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: Passing parameters to SQL query</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Passing-parameters-to-SQL-query/m-p/75659#M21956</link>
      <description>Hi.&lt;BR /&gt;
&lt;BR /&gt;
Chris's solution is great under the 64K limit, I would go for that.&lt;BR /&gt;
&lt;BR /&gt;
Above that, best way would be to bulkload a temporary table with your list (into DB2), and then inner join it with the desired table. Of course, everything done with SQL Pass-Through.&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;</description>
      <pubDate>Thu, 15 Oct 2009 09:31:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Passing-parameters-to-SQL-query/m-p/75659#M21956</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-10-15T09:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: Passing parameters to SQL query</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Passing-parameters-to-SQL-query/m-p/75660#M21957</link>
      <description>Another (easier?) solution could be using the DBKEY= data set option:&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/acreldb/61890/HTML/default/a001371553.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/acreldb/61890/HTML/default/a001371553.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
      <pubDate>Thu, 15 Oct 2009 13:36:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Passing-parameters-to-SQL-query/m-p/75660#M21957</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2009-10-15T13:36:41Z</dc:date>
    </item>
  </channel>
</rss>

