<?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: Query using a list variable from a different dataset in Proc SQL in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Query-using-a-list-variable-from-a-different-dataset-in-Proc-SQL/m-p/468584#M70764</link>
    <description>&lt;P&gt;Since it looks like you're using SQL Pass through you cannot use the work data sets. SQL Pass through means all the work is handled on the server, and the SQL needs to be in the correct style for the server, not SAS SQL.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A common workaround is to create macro variables out of the list. Since it's only 10 IDs it works fine, if its bigger it becomes an issue. Macro variables have a limit of 64K characters.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*for character variables;
proc sql noprint;
select quote(name) into :name_list separated by ", " 
from sashelp.class 
where sex='F';
quit;

%put &amp;amp;name_list;


*for numeric variables;
proc sql noprint;
select distinct age into :age_list separated by ", " 
from sashelp.class 
where sex='F';
quit;

%put &amp;amp;age_list;


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can use the macro variable in the WHERE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where ID in (&amp;amp;name_list);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/214296"&gt;@Sports_addict&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a dataset (dataset1) with 10 columns. I would like to use one of the columns (ID)&amp;nbsp;as an input in proc sql to query a cloud server to retrieve more info.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is what I have so far, but it doesn't work:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;SQL&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;CONNECT&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;TO&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ODBC (DSN=&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'database_name'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;CREATE&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;TABLE&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; WORK.new_table &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;AS&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;SELECT&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; * &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;FROM&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; connection to odbc (&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; * &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; cloud_table&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size="2"&gt;&lt;FONT color="#0000ff"&gt;where&lt;/FONT&gt; (col_name &lt;FONT color="#0000ff"&gt;IN&lt;/FONT&gt; (&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;SELECT&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;COL1&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;FROM&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; WORK.DATASET1&lt;FONT face="Courier New"&gt;&lt;FONT size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;)) );&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;disconnect&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; odbc;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I were to write exact same proc with each uniqueID in ' ' then it works, for example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;SQL&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;CONNECT&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;TO&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ODBC (DSN=&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'database_name'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;CREATE&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;TABLE&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; WORK.new_table &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;AS&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;SELECT&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; * &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;FROM&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; connection to odbc (&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; * &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; cloud_table&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; (col_name &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;IN&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; (&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'id1'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'id2'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'id3', etc.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;)&lt;/P&gt;
&lt;P&gt;) );&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;disconnect&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; odbc;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 08 Jun 2018 03:19:58 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-06-08T03:19:58Z</dc:date>
    <item>
      <title>Query using a list variable from a different dataset in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Query-using-a-list-variable-from-a-different-dataset-in-Proc-SQL/m-p/468519#M70758</link>
      <description>&lt;P&gt;I have a dataset (dataset1) with 10 columns. I would like to use one of the columns (ID)&amp;nbsp;as an input in proc sql to query a cloud server to retrieve more info.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I have so far, but it doesn't work:&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;SQL&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;CONNECT&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;TO&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ODBC (DSN=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'database_name'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;CREATE&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;TABLE&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; WORK.new_table &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;AS&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;SELECT&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; * &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;FROM&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; connection to odbc (&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; * &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; cloud_table&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size="2"&gt;&lt;FONT color="#0000ff"&gt;where&lt;/FONT&gt; (col_name &lt;FONT color="#0000ff"&gt;IN&lt;/FONT&gt; (&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;SELECT&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;COL1&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;FROM&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; WORK.DATASET1&lt;FONT face="Courier New"&gt;&lt;FONT size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;)) );&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;disconnect&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; odbc;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I were to write exact same proc with each uniqueID in ' ' then it works, for example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;SQL&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;CONNECT&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;TO&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ODBC (DSN=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'database_name'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;CREATE&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;TABLE&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; WORK.new_table &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;AS&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;SELECT&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; * &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;FROM&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; connection to odbc (&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; * &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; cloud_table&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; (col_name &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;IN&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; (&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'id1'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'id2'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'id3', etc.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;)&lt;/P&gt;&lt;P&gt;) );&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;disconnect&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; odbc;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jun 2018 20:13:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Query-using-a-list-variable-from-a-different-dataset-in-Proc-SQL/m-p/468519#M70758</guid>
      <dc:creator>Sports_addict</dc:creator>
      <dc:date>2018-06-07T20:13:18Z</dc:date>
    </item>
    <item>
      <title>Re: Query using a list variable from a different dataset in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Query-using-a-list-variable-from-a-different-dataset-in-Proc-SQL/m-p/468531#M70759</link>
      <description>&lt;P&gt;One common way to select records from a second data set where the value of one or more variables is used to select is a left (or right) join.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A brief example:&lt;/P&gt;
&lt;PRE&gt;data work.one;
   sex='M';
run;

proc sql;
   create table work.example as
   select b.*
   from work.one as a
        left join
        sashelp.class as b
        on a.sex=b.sex
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;The data set work.one&amp;nbsp;is just to create something to look up. The "as a"&amp;nbsp;and "as b" are&amp;nbsp;alias names so I can reference the data sets easier using aliasname.variablename. The ON says to select the records where the value of sex matches in both data sets and keep all the variables from data set alias b in the result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your data set can have multiple values like id to match on and you will get all of the records from the second set.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jun 2018 21:04:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Query-using-a-list-variable-from-a-different-dataset-in-Proc-SQL/m-p/468531#M70759</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-06-07T21:04:27Z</dc:date>
    </item>
    <item>
      <title>Re: Query using a list variable from a different dataset in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Query-using-a-list-variable-from-a-different-dataset-in-Proc-SQL/m-p/468584#M70764</link>
      <description>&lt;P&gt;Since it looks like you're using SQL Pass through you cannot use the work data sets. SQL Pass through means all the work is handled on the server, and the SQL needs to be in the correct style for the server, not SAS SQL.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A common workaround is to create macro variables out of the list. Since it's only 10 IDs it works fine, if its bigger it becomes an issue. Macro variables have a limit of 64K characters.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*for character variables;
proc sql noprint;
select quote(name) into :name_list separated by ", " 
from sashelp.class 
where sex='F';
quit;

%put &amp;amp;name_list;


*for numeric variables;
proc sql noprint;
select distinct age into :age_list separated by ", " 
from sashelp.class 
where sex='F';
quit;

%put &amp;amp;age_list;


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can use the macro variable in the WHERE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where ID in (&amp;amp;name_list);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/214296"&gt;@Sports_addict&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a dataset (dataset1) with 10 columns. I would like to use one of the columns (ID)&amp;nbsp;as an input in proc sql to query a cloud server to retrieve more info.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is what I have so far, but it doesn't work:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;SQL&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;CONNECT&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;TO&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ODBC (DSN=&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'database_name'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;CREATE&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;TABLE&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; WORK.new_table &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;AS&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;SELECT&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; * &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;FROM&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; connection to odbc (&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; * &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; cloud_table&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size="2"&gt;&lt;FONT color="#0000ff"&gt;where&lt;/FONT&gt; (col_name &lt;FONT color="#0000ff"&gt;IN&lt;/FONT&gt; (&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;SELECT&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;COL1&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;FROM&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; WORK.DATASET1&lt;FONT face="Courier New"&gt;&lt;FONT size="2"&gt;&lt;FONT face="Courier New" size="2"&gt;)) );&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;disconnect&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; odbc;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I were to write exact same proc with each uniqueID in ' ' then it works, for example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;SQL&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;CONNECT&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;TO&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ODBC (DSN=&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'database_name'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;CREATE&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;TABLE&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; WORK.new_table &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;AS&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;SELECT&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; * &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;FROM&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; connection to odbc (&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; * &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; cloud_table&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; (col_name &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;IN&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; (&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'id1'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'id2'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'id3', etc.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;)&lt;/P&gt;
&lt;P&gt;) );&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;disconnect&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; odbc;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jun 2018 03:19:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Query-using-a-list-variable-from-a-different-dataset-in-Proc-SQL/m-p/468584#M70764</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-08T03:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: Query using a list variable from a different dataset in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Query-using-a-list-variable-from-a-different-dataset-in-Proc-SQL/m-p/468702#M70766</link>
      <description>&lt;P&gt;Thanks a bunch! I was able to retrieve data from the&amp;nbsp;table with only minor changes. I had to use &lt;SPAN class="token function"&gt;quote&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;((strip(&lt;/SPAN&gt;name&lt;SPAN class="token punctuation"&gt;), "'")&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN class="token keyword"&gt;into&lt;/SPAN&gt; :name_list this let me search the sql table. Note it's&amp;nbsp;single quote inside " ".&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jun 2018 13:51:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Query-using-a-list-variable-from-a-different-dataset-in-Proc-SQL/m-p/468702#M70766</guid>
      <dc:creator>Sports_addict</dc:creator>
      <dc:date>2018-06-08T13:51:40Z</dc:date>
    </item>
  </channel>
</rss>

