<?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: combine multiple tables(&amp;gt;10) into one by using macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/combine-multiple-tables-gt-10-into-one-by-using-macro/m-p/562877#M157740</link>
    <description>&lt;P&gt;To confirm. You have a few tables that you would like to pull and merge together to create one table and you won't know how many tables are going to be merged?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should look into dictionary.tables. If they are in the same library or having a specific naming convention you can find them and store the names in a macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://go.documentation.sas.com/?docsetId=sqlproc&amp;amp;docsetTarget=n02s19q65mw08gn140bwfdh7spx7.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://go.documentation.sas.com/?docsetId=sqlproc&amp;amp;docsetTarget=n02s19q65mw08gn140bwfdh7spx7.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a program that could work, but I have made some assumptions:&lt;/P&gt;
&lt;P&gt;- All tables have a specific naming convention&lt;/P&gt;
&lt;P&gt;- All tables have the same name column to merge on&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Create the tables*/
data input_dates1;
length dt $9;
input dt;
dtnum1 +1;
value1=1111;
datalines;
01JAN1950
01JUL1950
;
run;

data input_dates2;
length dt $9;
input dt;
dtnum2 +1;
value2=22222;
datalines;
01JAN1950
01JUL1950
;
run;

data input_dates3;
length dt $9;
input dt;
dtnum3 +1;
value3=33333;
datalines;
01JAN1950
01JUL1950
;
run;

/*Use dictionary.tables to find specific tables. View all here*/
proc sql inobs=50;
select *
	from dictionary.tables;
quit;

/*Create a list the tables you would like and store in macro. I make the assumption they all start with 
INPUT_DATES and end with a number. You could also place all the tables in one specific library and remove memname=.*/
proc sql; /*Add noprint after validated*/ 
select memname
    into :tables separated by " "
from dictionary.tables
where libname="WORK" and memname like "INPUT_DATES_"; 
quit;
%put &amp;amp;=tables; /*View the list of tables I want*/


data want;
   merge &amp;amp;tables;
   by dt;
run;


/************************************/
/*Code from above in a macro program*/
/************************************/
%macro aaa(lib,tableprefix);
%let lib=%upcase(&amp;amp;lib);
%let tableprefix=%upcase(&amp;amp;tableprefix);

proc sql noprint; 
select memname
    into :tables separated by " "
from dictionary.tables
where libname="&amp;amp;lib" and memname like "&amp;amp;tableprefix"; 
quit;
%put &amp;amp;=tables;

data want;
   merge &amp;amp;tables;
   by dt;
run;

%mend aaa;

%aaa(work,input_dates_)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 31 May 2019 15:04:12 GMT</pubDate>
    <dc:creator>Panagiotis</dc:creator>
    <dc:date>2019-05-31T15:04:12Z</dc:date>
    <item>
      <title>combine multiple tables(&gt;10) into one by using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/combine-multiple-tables-gt-10-into-one-by-using-macro/m-p/562624#M157625</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a goal to craft one table as an output of a several ones. The quantity of tables being combined may differ(in example i've put 2).&lt;/P&gt;&lt;P&gt;I am thinking already rather much time, but i still cant catch an idea how could I to match all tables into one...&lt;/P&gt;&lt;P&gt;If anyone can help, i'll be very grateful.&lt;/P&gt;&lt;P&gt;(version SAS 9.4)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data input_dates;
length dt $9;
input dt;
dtnum +1;
datalines;
01JAN1950
01JUL1950
;
run;

proc sql noprint; select count(*) into: dtcnt from input_dates; quit;

%macro aaa;
%do i=1 %to &amp;amp;dtcnt;
proc sql noprint; select dt into: rdate from input_dates where dtnum = &amp;amp;dtcnt; quit;

proc sql;
    create table a1 as
    select date, air
    from sashelp.airline
    where date &amp;lt; "&amp;amp;rdate."d
    order by date desc;

    create table a11 as
    select date, air
    from a1(firstobs=1 obs=1);
quit;

data want;
merge a11;  /*i want here(or mabe in another place if need) to merge somehow all the tables with names a11*/
run;

%end
%mend aaa

%aaa&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TY!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 May 2019 16:49:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/combine-multiple-tables-gt-10-into-one-by-using-macro/m-p/562624#M157625</guid>
      <dc:creator>Ivan555</dc:creator>
      <dc:date>2019-05-30T16:49:56Z</dc:date>
    </item>
    <item>
      <title>Re: combine multiple tables(&gt;10) into one by using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/combine-multiple-tables-gt-10-into-one-by-using-macro/m-p/562877#M157740</link>
      <description>&lt;P&gt;To confirm. You have a few tables that you would like to pull and merge together to create one table and you won't know how many tables are going to be merged?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should look into dictionary.tables. If they are in the same library or having a specific naming convention you can find them and store the names in a macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://go.documentation.sas.com/?docsetId=sqlproc&amp;amp;docsetTarget=n02s19q65mw08gn140bwfdh7spx7.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://go.documentation.sas.com/?docsetId=sqlproc&amp;amp;docsetTarget=n02s19q65mw08gn140bwfdh7spx7.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a program that could work, but I have made some assumptions:&lt;/P&gt;
&lt;P&gt;- All tables have a specific naming convention&lt;/P&gt;
&lt;P&gt;- All tables have the same name column to merge on&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Create the tables*/
data input_dates1;
length dt $9;
input dt;
dtnum1 +1;
value1=1111;
datalines;
01JAN1950
01JUL1950
;
run;

data input_dates2;
length dt $9;
input dt;
dtnum2 +1;
value2=22222;
datalines;
01JAN1950
01JUL1950
;
run;

data input_dates3;
length dt $9;
input dt;
dtnum3 +1;
value3=33333;
datalines;
01JAN1950
01JUL1950
;
run;

/*Use dictionary.tables to find specific tables. View all here*/
proc sql inobs=50;
select *
	from dictionary.tables;
quit;

/*Create a list the tables you would like and store in macro. I make the assumption they all start with 
INPUT_DATES and end with a number. You could also place all the tables in one specific library and remove memname=.*/
proc sql; /*Add noprint after validated*/ 
select memname
    into :tables separated by " "
from dictionary.tables
where libname="WORK" and memname like "INPUT_DATES_"; 
quit;
%put &amp;amp;=tables; /*View the list of tables I want*/


data want;
   merge &amp;amp;tables;
   by dt;
run;


/************************************/
/*Code from above in a macro program*/
/************************************/
%macro aaa(lib,tableprefix);
%let lib=%upcase(&amp;amp;lib);
%let tableprefix=%upcase(&amp;amp;tableprefix);

proc sql noprint; 
select memname
    into :tables separated by " "
from dictionary.tables
where libname="&amp;amp;lib" and memname like "&amp;amp;tableprefix"; 
quit;
%put &amp;amp;=tables;

data want;
   merge &amp;amp;tables;
   by dt;
run;

%mend aaa;

%aaa(work,input_dates_)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2019 15:04:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/combine-multiple-tables-gt-10-into-one-by-using-macro/m-p/562877#M157740</guid>
      <dc:creator>Panagiotis</dc:creator>
      <dc:date>2019-05-31T15:04:12Z</dc:date>
    </item>
    <item>
      <title>Re: combine multiple tables(&gt;10) into one by using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/combine-multiple-tables-gt-10-into-one-by-using-macro/m-p/562884#M157743</link>
      <description>&lt;P&gt;Your program example doesn't match your description.&amp;nbsp; You talk about combining multiple tables, but in your example you just seem to be pulling different values from one table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2019 15:19:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/combine-multiple-tables-gt-10-into-one-by-using-macro/m-p/562884#M157743</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-31T15:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: combine multiple tables(&gt;10) into one by using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/combine-multiple-tables-gt-10-into-one-by-using-macro/m-p/563226#M157867</link>
      <description>&lt;P&gt;Fist of all &lt;STRONG&gt;&lt;U&gt;sorry&lt;/U&gt;&lt;/STRONG&gt;, seems I've done multiposting, but that wasn't done on purpose, just maybe in case of a long moderation time..&lt;/P&gt;&lt;P&gt;(another post:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/combining-multiple-tables-qty-various-in-one-dataset-table-by/m-p/562778#M157698" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/combining-multiple-tables-qty-various-in-one-dataset-table-by/m-p/562778#M157698 )&lt;/A&gt;&lt;/P&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;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/152214"&gt;@Panagiotis&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;About the subject: as I see it - I have dates table which in example has 2 rows, but in life can have 10-50 rows or more.&lt;/P&gt;&lt;P&gt;For each datevalue I thought to make a single output table. After, I thought to make one huge table being base on the output ones.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Finally, after thinking, I've reached a result which I expected(solvation for me was in proc append), but maybe it is not the most optimal way - I am rather new both in SAS and SQL, so I can't judge about it..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code: (output_date = want)&lt;/P&gt;&lt;PRE&gt;data input_dates;
length dt $9;
input dt;
dtnum +1;
datalines;
01JAN1950
01JUL1950
;
run;

data output_dates;
input DATE;
format DATE date9.;
input AIR;
format AIR int;
datalines;
;

proc sql noprint; select count(*) into: dtcnt from input_dates; quit;

%macro aaa;
%do i=1 %to &amp;amp;dtcnt;
proc sql noprint; select dt into: rdate from input_dates where dtnum = &amp;amp;i; quit;

proc sql;
    create table a1 as
    select date, air
    from sashelp.airline
    where date &amp;lt; "&amp;amp;rdate."d
    order by date desc;

    create table a11 as
    select date, air
    from a1(firstobs=1 obs=1);
quit;

proc append base = output_dates data = a11;
run;

%end
%mend aaa

%aaa&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2019 10:56:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/combine-multiple-tables-gt-10-into-one-by-using-macro/m-p/563226#M157867</guid>
      <dc:creator>Ivan555</dc:creator>
      <dc:date>2019-06-03T10:56:18Z</dc:date>
    </item>
  </channel>
</rss>

