<?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 Trying to append a (variable) number of tables together within a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-append-a-variable-number-of-tables-together-within-a/m-p/476591#M122661</link>
    <description>&lt;P&gt;Hi everyone - am trying to design a loop to append a variable number of data tables together - there's a financial metric in monthly tables that I need to add up on, say a YTD basis.. so in&amp;nbsp;March would need to add the value of money_value for any given account in tables TABLE_2018_01, TABLE_2018_02 and TABLE_2018_03... but in&amp;nbsp;September&amp;nbsp;would need to also add TABLE_2018_04, 2018_05, etc through to TABLE_2018_09.&amp;nbsp; I can manually append these tables together, total the value by account of money_value, but want to automate this for flexible time periods.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've set up prompts to allow a user to select their end month, and have set up a macro variable to calculate the number of months between the start of year and whatever the end up is of the user - this all works for the purposes of various other data elements that I don't have to pull from individual tables,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, having trouble creating a loop&amp;nbsp;that could allow appending a non-static number of tables together based on the interval between the user defined end date and the start date.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;lt;prompts&amp;nbsp;runs, get user to select a month saved to %extract_month_end&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;/* generate macro variables&amp;nbsp;*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;%let&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;interval&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN&gt;(intck(month,"31DEC2017"d,"&amp;amp;extract_month_end"d));&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;STRONG&gt;&lt;SPAN&gt;run&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;STRONG&gt;&lt;SPAN&gt;%macro&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;generate_data;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;data&amp;nbsp;first_table;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;set table_2018_01;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;%let&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;i=0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;%DO&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;%UNTIL&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;(&amp;amp;i=&amp;amp;interval)&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;%let&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;i=i&amp;amp;+1&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;%let&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;ym_seq =&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN&gt;(intnx(month,"&amp;amp;extract_month_end"d,+i,e),yymmn6.);&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;%let&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;year_month_seq =&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN&gt;(substr(&amp;amp;ym_seq,1,4))_&lt;/SPAN&gt;&lt;SPAN&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN&gt;(substr(ym_seq,5));&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc append base=first_table&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data=TABLE_year_month_seq;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;%end&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;&amp;lt;numerous other things which are working fine&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;%mend;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;Any advice here would be appreciated!&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 09 Jul 2018 20:32:02 GMT</pubDate>
    <dc:creator>nvd</dc:creator>
    <dc:date>2018-07-09T20:32:02Z</dc:date>
    <item>
      <title>Trying to append a (variable) number of tables together within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-append-a-variable-number-of-tables-together-within-a/m-p/476591#M122661</link>
      <description>&lt;P&gt;Hi everyone - am trying to design a loop to append a variable number of data tables together - there's a financial metric in monthly tables that I need to add up on, say a YTD basis.. so in&amp;nbsp;March would need to add the value of money_value for any given account in tables TABLE_2018_01, TABLE_2018_02 and TABLE_2018_03... but in&amp;nbsp;September&amp;nbsp;would need to also add TABLE_2018_04, 2018_05, etc through to TABLE_2018_09.&amp;nbsp; I can manually append these tables together, total the value by account of money_value, but want to automate this for flexible time periods.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've set up prompts to allow a user to select their end month, and have set up a macro variable to calculate the number of months between the start of year and whatever the end up is of the user - this all works for the purposes of various other data elements that I don't have to pull from individual tables,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, having trouble creating a loop&amp;nbsp;that could allow appending a non-static number of tables together based on the interval between the user defined end date and the start date.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;lt;prompts&amp;nbsp;runs, get user to select a month saved to %extract_month_end&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;/* generate macro variables&amp;nbsp;*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;%let&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;interval&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN&gt;(intck(month,"31DEC2017"d,"&amp;amp;extract_month_end"d));&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;STRONG&gt;&lt;SPAN&gt;run&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;STRONG&gt;&lt;SPAN&gt;%macro&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;generate_data;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;data&amp;nbsp;first_table;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;set table_2018_01;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;%let&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;i=0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;%DO&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;%UNTIL&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;(&amp;amp;i=&amp;amp;interval)&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;%let&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;i=i&amp;amp;+1&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;%let&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;ym_seq =&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN&gt;(intnx(month,"&amp;amp;extract_month_end"d,+i,e),yymmn6.);&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;%let&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;year_month_seq =&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN&gt;(substr(&amp;amp;ym_seq,1,4))_&lt;/SPAN&gt;&lt;SPAN&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN&gt;(substr(ym_seq,5));&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc append base=first_table&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data=TABLE_year_month_seq;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;%end&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;&amp;lt;numerous other things which are working fine&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;%mend;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&lt;SPAN&gt;Any advice here would be appreciated!&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="yiv2224360794MsoNormal"&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jul 2018 20:32:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-append-a-variable-number-of-tables-together-within-a/m-p/476591#M122661</guid>
      <dc:creator>nvd</dc:creator>
      <dc:date>2018-07-09T20:32:02Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to append a (variable) number of tables together within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-append-a-variable-number-of-tables-together-within-a/m-p/476641#M122678</link>
      <description>&lt;P&gt;Instead of building N proc appends, make a space-separated list of N dataset names to put in a SET statement, producing something like.&amp;nbsp; If N=9 it would be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; set&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; table_2018_01&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; table_2018_02&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; table_2018_09&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  %let interval = %sysfunc(intck(month,"31DEC2017"d,"&amp;amp;extract_month_end"d));

%macro generate_data;
  %let dslist=;
  %do i=1 %to &amp;amp;interval;
    %let yyyy_mm=%sysfunc(intnx(month,"31dec2017"d,&amp;amp;i,e),yymm7.);
    %let yyyy_mm=%sysfunc(tranwrd(&amp;amp;yyyy_mm,M,_)); /*Change 2018M02 to 2018_02*/
    %let dslist=&amp;amp;dslist TABLE_&amp;amp;yyyy_mm;
  %end;
 
  data want;
    set &amp;amp;dslist ;
  run;
     &amp;lt;numerous other things which are working fine&amp;gt;
%mend;


options mprint;
%generate_data;

  
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Jul 2018 01:13:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-append-a-variable-number-of-tables-together-within-a/m-p/476641#M122678</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-07-10T01:13:45Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to append a (variable) number of tables together within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-append-a-variable-number-of-tables-together-within-a/m-p/476679#M122683</link>
      <description>&lt;P&gt;Hi you could use the SAS metadata to Loop over the requested datasets.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro append(dsn);
proc append base=alldata data=&amp;amp;dsn;
run;
%mend append;

proc format; 
  picture x_yyyy_mm (default=7)
    low - high = '%Y_%0m' (datatype=date)
  ;
run; 

%let start=30NOV2017;
%let end=28FEB2018;

data _NULL_;
   set sashelp.vtable;
   where libname eq 'WORK' 
   and index(memname,'TABLE_') 
   and substr(memname,7) gt put("&amp;amp;start."d,x_yyyy_mm.) 
   and substr(memname,7) le put("&amp;amp;end."d,x_yyyy_mm.);
   call execute('%nrstr(%append('||strip(libname)||'.'||strip(memname)||'))');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Jul 2018 07:22:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-append-a-variable-number-of-tables-together-within-a/m-p/476679#M122683</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2018-07-10T07:22:36Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to append a (variable) number of tables together within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-append-a-variable-number-of-tables-together-within-a/m-p/476806#M122731</link>
      <description>&lt;P&gt;Thanks - worked like a charm.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jul 2018 13:43:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-append-a-variable-number-of-tables-together-within-a/m-p/476806#M122731</guid>
      <dc:creator>nvd</dc:creator>
      <dc:date>2018-07-10T13:43:26Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to append a (variable) number of tables together within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-append-a-variable-number-of-tables-together-within-a/m-p/476993#M122779</link>
      <description>&lt;P&gt;The problem I see with your 'interval' method is that you append as many tables as you need without checking how many tables you actually have in your 'interval'.&lt;BR /&gt;If you ever miss a table in your interval, you will erroneously append the table of the following month(!)&lt;BR /&gt;One other thing is that it crashes if you ever try to calculate within years. (ie. from Aug2016 to Feb2017)&lt;BR /&gt;And one last thing is that proc append was more efficient and warns in case one of your table do not match the database structure of the first table.&lt;BR /&gt;I would recommend a defensive approach especially in the financial sector.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jul 2018 07:29:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-append-a-variable-number-of-tables-together-within-a/m-p/476993#M122779</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2018-07-11T07:29:37Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to append a (variable) number of tables together within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-append-a-variable-number-of-tables-together-within-a/m-p/477135#M122833</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/77163"&gt;@Oligolas&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The problem I see with your 'interval' method is that you append as many tables as you need without checking how many tables you actually have in your 'interval'.&lt;BR /&gt;If you ever miss a table in your interval, you will erroneously append the table of the following month(!)&lt;BR /&gt;One other thing is that it crashes if you ever try to calculate within years. (ie. from Aug2016 to Feb2017)&lt;BR /&gt;And one last thing is that proc append was more efficient and warns in case one of your table do not match the database structure of the first table.&lt;BR /&gt;I would recommend a defensive approach especially in the financial sector.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good point on defending against missing tables,&amp;nbsp;but that can be easily addressed within the interval approach, by testing for existence while building the DSLIST macrovar.&amp;nbsp; This code skips absent months:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro generate_data;
  %let dslist=;
  %do i=1 %to &amp;amp;interval;
    %let yyyy_mm=%sysfunc(intnx(month,"31dec2017"d,&amp;amp;i,e),yymm7.);
    %let yyyy_mm=%sysfunc(tranwrd(&amp;amp;yyyy_mm,M,_)); /*Change 2018M02 to 2018_02*/
    %if %sysfunc(exist(work.TABLE_&amp;amp;yyyy_mm)) %then
    %let dslist=&amp;amp;dslist TABLE_&amp;amp;yyyy_mm;
  %end;
 
  data want;
    set &amp;amp;dslist ;
  run;
     &amp;lt;numerous other things which are working fine&amp;gt;

%mend;

options mprint;
%let interval=5;
%generate_data;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if the users want to terminate the macro whenever a month is missing, then following the "%if sysfunc..." statement with&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; %else %return;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't understand the crash prediction "if you every try to calculate within years"&amp;nbsp;&amp;nbsp; (actually I think you mean across years, but I still don't understand the crash prediction).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my experience I haven't encounter a situation in which multiple proc appends is a more efficient approach than multiple arguments to a single SET statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As to the protection append offers against mixed database structures, if the OP's production environment is like those I have seen, a collection of dataset names like TABLE_2018_01 TABLE_2018_02, etc. means identical structures.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, the SET statement will stop the data step when a variable is numeric in some datasets and character in others.&amp;nbsp; And in addition you can add the "open=defer" option to the SET statement, as in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set &amp;amp;dslist&amp;nbsp; open=defer;&lt;/P&gt;
&lt;P&gt;which will (1) force the output dataset to only get variables in the first name in &amp;amp;dslist, and (2) issue warnings on the log when any dataset has a differing structure.&amp;nbsp;&amp;nbsp; It also saves memory, since it tells SAS to re-user the same input buffer for each dataset rather than set up a buffer for each dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, I agree with the idea of a defensive approach, but I'm not sure the 'interval' method is intrinsically less defensive.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jul 2018 15:48:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-append-a-variable-number-of-tables-together-within-a/m-p/477135#M122833</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-07-11T15:48:19Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to append a (variable) number of tables together within a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-append-a-variable-number-of-tables-together-within-a/m-p/477370#M122930</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;maybe the approaches and experiences between the finance and pharmaceutical sector are different.&lt;BR /&gt;With 'calculation within years' I meant starting from a month other than december 2017 let's say November 2017 (it raises an intnx error) but maybe it is not relevant because calculations are only done within a year. nvm.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2018 08:50:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-append-a-variable-number-of-tables-together-within-a/m-p/477370#M122930</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2018-07-12T08:50:47Z</dc:date>
    </item>
  </channel>
</rss>

