<?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: proc sql - how to select variables that are values in another table in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-how-to-select-variables-that-are-values-in-another/m-p/38531#M9888</link>
    <description>to follow up on the post...&lt;BR /&gt;
&lt;BR /&gt;
VARS&lt;BR /&gt;
"Age"&lt;BR /&gt;
"Gender"&lt;BR /&gt;
"Height"&lt;BR /&gt;
"Weight"&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
select vars into :VarStmt separated by ', '&lt;BR /&gt;
from VARS;&lt;BR /&gt;
&lt;BR /&gt;
select &amp;amp;VarStmt from Table_B;&lt;BR /&gt;
quit;</description>
    <pubDate>Sat, 26 Mar 2011 12:36:50 GMT</pubDate>
    <dc:creator>DBailey</dc:creator>
    <dc:date>2011-03-26T12:36:50Z</dc:date>
    <item>
      <title>proc sql - how to select variables that are values in another table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-how-to-select-variables-that-are-values-in-another/m-p/38529#M9886</link>
      <description>I have a variable (e.g., VARS) in Table_A that contains a list of variables to be selected from Table_B.&lt;BR /&gt;
&lt;BR /&gt;
VARS&lt;BR /&gt;
====&lt;BR /&gt;
"Age"&lt;BR /&gt;
"Gender"&lt;BR /&gt;
"Height"&lt;BR /&gt;
"Weight"&lt;BR /&gt;
...&lt;BR /&gt;
&lt;BR /&gt;
Table B contains variables as named above among many other variables. I would like to select only those variables in VARS from Table B. Here's a code I used:&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  select (select VARS from Table_A)&lt;BR /&gt;
  from Table_B;&lt;BR /&gt;
run; &lt;BR /&gt;
&lt;BR /&gt;
Of course, I got an error message: "ERROR: Subquery evaluated to more than one row."&lt;BR /&gt;
&lt;BR /&gt;
Is there a way to achieve this in proc sql? I know how to do this by creating %macro variables. &lt;BR /&gt;
&lt;BR /&gt;
Many thanks,</description>
      <pubDate>Fri, 25 Mar 2011 21:38:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-how-to-select-variables-that-are-values-in-another/m-p/38529#M9886</guid>
      <dc:creator>choi</dc:creator>
      <dc:date>2011-03-25T21:38:57Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql - how to select variables that are values in another table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-how-to-select-variables-that-are-values-in-another/m-p/38530#M9887</link>
      <description>There is probably a more direct way, but the following example should work:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data a;&lt;BR /&gt;
  input a b c d e f;&lt;BR /&gt;
  cards;&lt;BR /&gt;
1 2 3 4 5 6&lt;BR /&gt;
7 8 9 10 11 12&lt;BR /&gt;
;&lt;BR /&gt;
data b;&lt;BR /&gt;
  input a b c;&lt;BR /&gt;
  cards;&lt;BR /&gt;
1 2 3&lt;BR /&gt;
4 5 6&lt;BR /&gt;
;&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
  select name into :names&lt;BR /&gt;
    separated by ","&lt;BR /&gt;
      from dictionary.columns&lt;BR /&gt;
        where libname eq "WORK" and&lt;BR /&gt;
              memname eq "B"&lt;BR /&gt;
  ;&lt;BR /&gt;
&lt;BR /&gt;
  create table want as&lt;BR /&gt;
    select &amp;amp;names.&lt;BR /&gt;
      from A&lt;BR /&gt;
;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
HTH,&lt;BR /&gt;
Art</description>
      <pubDate>Fri, 25 Mar 2011 23:15:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-how-to-select-variables-that-are-values-in-another/m-p/38530#M9887</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-03-25T23:15:19Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql - how to select variables that are values in another table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-how-to-select-variables-that-are-values-in-another/m-p/38531#M9888</link>
      <description>to follow up on the post...&lt;BR /&gt;
&lt;BR /&gt;
VARS&lt;BR /&gt;
"Age"&lt;BR /&gt;
"Gender"&lt;BR /&gt;
"Height"&lt;BR /&gt;
"Weight"&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
select vars into :VarStmt separated by ', '&lt;BR /&gt;
from VARS;&lt;BR /&gt;
&lt;BR /&gt;
select &amp;amp;VarStmt from Table_B;&lt;BR /&gt;
quit;</description>
      <pubDate>Sat, 26 Mar 2011 12:36:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-how-to-select-variables-that-are-values-in-another/m-p/38531#M9888</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2011-03-26T12:36:50Z</dc:date>
    </item>
  </channel>
</rss>

