<?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 Automatically select and append tables from the library in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Automatically-select-and-append-tables-from-the-library/m-p/728395#M226646</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I would like to automatically select tables from the library and append them all. Before that I need also a new variable in each table with date to&amp;nbsp;distinguish them.&lt;/P&gt;
&lt;P&gt;Each table is named according to the scheme ODSHMS.TABLE_202101. The names differ by a different date at the end like ODSHMS.TABLE_202102, ODSHMS.TABLE_202103 etc. The table example looks like this:&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="50%" height="29px"&gt;ID&lt;/TD&gt;
&lt;TD width="50%" height="29px"&gt;VAR&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="29px"&gt;1&lt;/TD&gt;
&lt;TD width="50%" height="29px"&gt;YES&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="29px"&gt;2&lt;/TD&gt;
&lt;TD width="50%" height="29px"&gt;NO&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;After selecting the tables, adding the date variable from the table name and appending them it should look like below&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;ID&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;DATE&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;VAR&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;1&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;202102&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;YES&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;2&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;202102&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;NO&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;1&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;202103&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;NO&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;2&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;202103&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;YES&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;Can you help me with solution?&lt;/P&gt;</description>
    <pubDate>Tue, 23 Mar 2021 10:30:40 GMT</pubDate>
    <dc:creator>PatrykSAS</dc:creator>
    <dc:date>2021-03-23T10:30:40Z</dc:date>
    <item>
      <title>Automatically select and append tables from the library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatically-select-and-append-tables-from-the-library/m-p/728395#M226646</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I would like to automatically select tables from the library and append them all. Before that I need also a new variable in each table with date to&amp;nbsp;distinguish them.&lt;/P&gt;
&lt;P&gt;Each table is named according to the scheme ODSHMS.TABLE_202101. The names differ by a different date at the end like ODSHMS.TABLE_202102, ODSHMS.TABLE_202103 etc. The table example looks like this:&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="50%" height="29px"&gt;ID&lt;/TD&gt;
&lt;TD width="50%" height="29px"&gt;VAR&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="29px"&gt;1&lt;/TD&gt;
&lt;TD width="50%" height="29px"&gt;YES&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="29px"&gt;2&lt;/TD&gt;
&lt;TD width="50%" height="29px"&gt;NO&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;After selecting the tables, adding the date variable from the table name and appending them it should look like below&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;ID&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;DATE&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;VAR&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;1&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;202102&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;YES&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;2&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;202102&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;NO&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;1&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;202103&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;NO&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;2&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;202103&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="29px"&gt;YES&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;Can you help me with solution?&lt;/P&gt;</description>
      <pubDate>Tue, 23 Mar 2021 10:30:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatically-select-and-append-tables-from-the-library/m-p/728395#M226646</guid>
      <dc:creator>PatrykSAS</dc:creator>
      <dc:date>2021-03-23T10:30:40Z</dc:date>
    </item>
    <item>
      <title>Re: Automatically select and append tables from the library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatically-select-and-append-tables-from-the-library/m-p/728418#M226659</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below code may not be entirely correct as I have to type it "blindly" (i.e. without being able to run it and see the LOG).&lt;/P&gt;
&lt;P&gt;But you will surely get the idea.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL noprint;
 create table work.ds_to_append as
 select memname
 from dictionary.tables
 where libname='ODSHMS' and substr(memname,1,8) = 'TABLE_20';
QUIT;

data _NULL_;
 if 0 then set work.ds_to_append nobs=count;
 call symput('numobs',strip(put(count,8.)));
 STOP;
run;
%PUT &amp;amp;=numobs;

%MACRO append_loop;
%LOCAL i;

PROC DATASETS library=WORK NoList;
 delete appendresult / memtype=DATA; run;
QUIT;

%DO i = 1 %TO &amp;amp;numobs.;
data _NULL_;
 set work.ds_to_append(firstobs=&amp;amp;i. obs=&amp;amp;i.);
 call symput('memname'    ,       strip(memname)   );
 call symput('date_to_add',substr(strip(memname),7));
run;

data ODSHMS.&amp;amp;memname.;
 set ODSHMS.&amp;amp;memname.;
 datestamp=&amp;amp;date_to_add.;
run;

PROC APPEND base=work.appendresult data=ODSHMS.&amp;amp;memname.; run;
%END;
QUIT;
%MEND  append_loop;
options mprint symbolgen;
%append_loop
/* end of program */
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Mar 2021 12:46:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatically-select-and-append-tables-from-the-library/m-p/728418#M226659</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-03-23T12:46:57Z</dc:date>
    </item>
    <item>
      <title>Re: Automatically select and append tables from the library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatically-select-and-append-tables-from-the-library/m-p/728427#M226660</link>
      <description>&lt;P&gt;Try this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
 	select cats('ODSHMS.',MEMNAME) into :datasets separated by ' '
 	from dictionary.tables
 	where LIBNAME = 'ODSHMS' and MEMNAME like 'TABLE_20%';
quit;

data combined;
	set &amp;amp;datasets indsname=DS;
	DATE = scan(DS,2,'_');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Mar 2021 13:31:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatically-select-and-append-tables-from-the-library/m-p/728427#M226660</guid>
      <dc:creator>Athenkosi</dc:creator>
      <dc:date>2021-03-23T13:31:21Z</dc:date>
    </item>
    <item>
      <title>Re: Automatically select and append tables from the library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatically-select-and-append-tables-from-the-library/m-p/728429#M226662</link>
      <description>Works nice and easy, Thank you</description>
      <pubDate>Tue, 23 Mar 2021 13:43:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatically-select-and-append-tables-from-the-library/m-p/728429#M226662</guid>
      <dc:creator>PatrykSAS</dc:creator>
      <dc:date>2021-03-23T13:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: Automatically select and append tables from the library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatically-select-and-append-tables-from-the-library/m-p/728442#M226666</link>
      <description>&lt;P&gt;Just FYI, as I see the question has already been solved.&lt;/P&gt;
&lt;P&gt;Something like this works as well:&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;data combined;
 set ODSHMS.TABLE_202101-ODSHMS.TABLE_202112 indsname=dsn;
 datestamp=scan(dsn,2,'_');
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It's called: Using Data Set Lists with SET&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;... but it's obviously less generic as the previous two solutions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Tue, 23 Mar 2021 13:59:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatically-select-and-append-tables-from-the-library/m-p/728442#M226666</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-03-23T13:59:01Z</dc:date>
    </item>
  </channel>
</rss>

