<?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 a column with table names in a data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-column-with-table-names-in-a-data-step/m-p/576464#M163179</link>
    <description>&lt;P&gt;I liked this answer due to the fact (1) It was the first answer (2) I like the SAS approach. As a matter of improvement: Could you edit your answer such that you also add the answer of the colleague below ?:). I thought his answer was also good and easier to read.&lt;/P&gt;</description>
    <pubDate>Thu, 25 Jul 2019 06:51:32 GMT</pubDate>
    <dc:creator>carles</dc:creator>
    <dc:date>2019-07-25T06:51:32Z</dc:date>
    <item>
      <title>Passing a column with table names in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-column-with-table-names-in-a-data-step/m-p/576186#M163060</link>
      <description>&lt;P&gt;Let's assume I have two tables and I want to join them as following:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data Table1;
   input var$ ;
   datalines;
hello1
hello2
hello3
;
run;
data Table2;
   input var$ ;
   datalines;
hello1
hello2
hello4
;
run;
data Table3;
set Table1 Table2;
run; &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, let's imagine I have the names of the tables listed in a data table as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data TableNames;
   length Tablenames $ 12;
   input Tablenames $ ;
   datalines;
Table1
Table2
;&lt;/PRE&gt;&lt;P&gt;How could I do it to pass the values of that column to get the same as in Table 3 ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;P.D: I can only use base SAS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for the help in advanced;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jul 2019 14:58:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-a-column-with-table-names-in-a-data-step/m-p/576186#M163060</guid>
      <dc:creator>carles</dc:creator>
      <dc:date>2019-07-24T14:58:41Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a column with table names in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-column-with-table-names-in-a-data-step/m-p/576198#M163066</link>
      <description>&lt;P&gt;If I understand you correctly:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TableNames;
   length Tablenames $ 12;
   input Tablenames $ ;
   if tablenames = '*END*' then
      call symput('nrows', trim(_N_ -1));
   else
      call symput('Table'!!trim(_N_), trim(tablenames));
   datalines;
Table1
Table2
*END*
;
run;

%macro set_all;
   data want;
      set
      %do i=1 %to &amp;amp;nrows;
          &amp;amp;&amp;amp;Table&amp;amp;i
      %end;              /* fixed typos */
      ;
run;&lt;BR /&gt;%mend;&lt;BR /&gt;%set_all;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;'s solution is shorter and more elegant, using sql:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select tablenames
  into :tablelist separated by ' '
  from tablenames
;
quit;

data want;
  set &amp;amp;tablelist ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2019 13:37:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-a-column-with-table-names-in-a-data-step/m-p/576198#M163066</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-07-25T13:37:21Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a column with table names in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-column-with-table-names-in-a-data-step/m-p/576203#M163068</link>
      <description>&lt;P&gt;As long as the list of table names is small enough to fit in a macro variable (limit is 65K characters) it is probably easiest to just make a macro variable and use the macro variable to generate the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select tablenames
  into :tablelist separated by ' '
  from tablenames
;
quit;

data want;
  set &amp;amp;tablelist ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Jul 2019 15:23:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-a-column-with-table-names-in-a-data-step/m-p/576203#M163068</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-24T15:23:19Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a column with table names in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-column-with-table-names-in-a-data-step/m-p/576217#M163075</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname fart "&amp;amp;mypath.";
proc sql noprint ;
select 'FART.'|| memname into :mylist separated by ' '
from dictionary.tables
where libname='FART' and nobs&amp;gt;0
;
quit;


data want;
  set &amp;amp;mylist. ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Jul 2019 15:42:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-a-column-with-table-names-in-a-data-step/m-p/576217#M163075</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2019-07-24T15:42:53Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a column with table names in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-column-with-table-names-in-a-data-step/m-p/576464#M163179</link>
      <description>&lt;P&gt;I liked this answer due to the fact (1) It was the first answer (2) I like the SAS approach. As a matter of improvement: Could you edit your answer such that you also add the answer of the colleague below ?:). I thought his answer was also good and easier to read.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2019 06:51:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-a-column-with-table-names-in-a-data-step/m-p/576464#M163179</guid>
      <dc:creator>carles</dc:creator>
      <dc:date>2019-07-25T06:51:32Z</dc:date>
    </item>
    <item>
      <title>Re: Passing a column with table names in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-a-column-with-table-names-in-a-data-step/m-p/576465#M163180</link>
      <description>&lt;P&gt;Thank you so much for the answer. I have written to guy above to include in his answer yours such that overall answer gets improved. I have used though your answer becasue of easiness in understanding though generaly I prefer the SAS approach. For that, thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2019 06:53:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-a-column-with-table-names-in-a-data-step/m-p/576465#M163180</guid>
      <dc:creator>carles</dc:creator>
      <dc:date>2019-07-25T06:53:53Z</dc:date>
    </item>
  </channel>
</rss>

