<?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: Appending dated tables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Appending-dated-tables/m-p/440428#M110007</link>
    <description>&lt;P&gt;Thanks for the response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Found a round about way of doing it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;See below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;%let currentmonth=201601;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;%let currentyear=2016;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;%let currentmonth=01;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;EM&gt;%let previousmonth=201501;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;%let previousyear=2015;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;%let previousmonth=01;&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;EM&gt;Data Prevyear;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;set work.exp_&amp;amp;previousyear.&amp;amp;previousmonth.-work.exp_&amp;amp;previousyear.12;run;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;EM&gt;Data currentyear;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;set work.exp_&amp;amp;currentyear.01-work.exp_&amp;amp;currentyear.&amp;amp;currentmonth.;run;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;EM&gt;PROC SQL;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;CREATE TABLE WORK.Append_Table AS &lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;SELECT * FROM WORK.PREVYEAR&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;OUTER UNION CORR &lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;SELECT * FROM WORK.CURRENTYEAR&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;Quit;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;EM&gt;%put _all_;&lt;/EM&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 27 Feb 2018 10:14:00 GMT</pubDate>
    <dc:creator>Perreby</dc:creator>
    <dc:date>2018-02-27T10:14:00Z</dc:date>
    <item>
      <title>Appending dated tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-dated-tables/m-p/440398#M109990</link>
      <description>&lt;P&gt;Im pretty decent with SAS coding but have one thing that is getting the better of me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have various datasets that is dated for each month. Say X_201501, X_201502 ... X201601;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I would like a use to input the current month and 12months prior;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So %let currentmonth= 201601;&lt;/P&gt;&lt;P&gt;&amp;nbsp;and %let previousyearmonth=201501;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would then like to append all the tables from 201501 to 201601.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data Combined;&lt;/P&gt;&lt;P&gt;set X_&amp;amp;currentmonth.- X_&amp;amp;previousyearmonth.;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is that it is now looking for tables such as 201579 and 201580 all the way until it gets to 201601.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But we all know there are only 12months in a year. So essentially it should only look for the following tables:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;X_201501, &lt;SPAN&gt;X_&lt;/SPAN&gt;201502, &lt;SPAN&gt;X_&lt;/SPAN&gt;201503, &lt;SPAN&gt;X_&lt;/SPAN&gt;201504, &lt;SPAN&gt;X_&lt;/SPAN&gt;201505, &lt;SPAN&gt;X_&lt;/SPAN&gt;201506, &lt;SPAN&gt;X_&lt;/SPAN&gt;201507, &lt;SPAN&gt;X_&lt;/SPAN&gt;201508, &lt;SPAN&gt;X_&lt;/SPAN&gt;201509,&lt;SPAN&gt;X_&lt;/SPAN&gt;201510,&lt;SPAN&gt;X_&lt;/SPAN&gt;201511, &lt;SPAN&gt;X_&lt;/SPAN&gt;01512, &lt;SPAN&gt;X_&lt;/SPAN&gt;201601&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So how does one code this so SAS only adds the above tables. The ideal would be that I dont have to request users to input all the above 12months in the data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Riaan&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2018 07:48:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-dated-tables/m-p/440398#M109990</guid>
      <dc:creator>Perreby</dc:creator>
      <dc:date>2018-02-27T07:48:58Z</dc:date>
    </item>
    <item>
      <title>Re: Appending dated tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-dated-tables/m-p/440404#M109993</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;try this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x_201501 X_201502 X201601 X201602;
   length ds $20;
   set sashelp.class;
run;

%symdel dsnames inputds /nowarn;
%let inputds=X201601;
PROC SQL noprint;
   select memname into :dsnames separated by ' '
   from sashelp.vtable
   where libname eq 'WORK'
   and intnx('year',input(compress("&amp;amp;inputds.",,'dk'),yymmn6.),-1)&amp;lt;=input(compress(memname,,'dk'),yymmn6.)&amp;lt;=input(compress("&amp;amp;inputds.",,'dk'),yymmn6.)
   ;
QUIT;
%put &amp;amp;=dsnames.;

data combined;
   set &amp;amp;dsnames.;
run;
%symdel dsnames inputds;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Feb 2018 08:47:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-dated-tables/m-p/440404#M109993</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2018-02-27T08:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: Appending dated tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-dated-tables/m-p/440419#M110000</link>
      <description>&lt;P&gt;Why are the data stored like that?&amp;nbsp; From a storage point of view having multiple tables with similar data is inefficient - you have the extra overhead not only of the header block, but a read/write on each.&amp;nbsp; From a programming point of view it is inefficient - as you are finding now, trying to code with such a setup is a nightmare, creating masses of messy macro code.&amp;nbsp; Imagine how much simpler life would be if you stored all that data in one big dataset, with a column (you know those parts of the datasets used to capture data) for date, then your code would be as simple as:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  where date between today() and intnx('month',today(),-1);
run;&lt;/PRE&gt;
&lt;P&gt;Its your data modelling causing your issues - and most likely issues across the board.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2018 09:58:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-dated-tables/m-p/440419#M110000</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-02-27T09:58:35Z</dc:date>
    </item>
    <item>
      <title>Re: Appending dated tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-dated-tables/m-p/440428#M110007</link>
      <description>&lt;P&gt;Thanks for the response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Found a round about way of doing it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;See below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;%let currentmonth=201601;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;%let currentyear=2016;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;%let currentmonth=01;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;EM&gt;%let previousmonth=201501;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;%let previousyear=2015;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;%let previousmonth=01;&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;EM&gt;Data Prevyear;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;set work.exp_&amp;amp;previousyear.&amp;amp;previousmonth.-work.exp_&amp;amp;previousyear.12;run;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;EM&gt;Data currentyear;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;set work.exp_&amp;amp;currentyear.01-work.exp_&amp;amp;currentyear.&amp;amp;currentmonth.;run;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;EM&gt;PROC SQL;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;CREATE TABLE WORK.Append_Table AS &lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;SELECT * FROM WORK.PREVYEAR&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;OUTER UNION CORR &lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;SELECT * FROM WORK.CURRENTYEAR&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;Quit;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;EM&gt;%put _all_;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2018 10:14:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-dated-tables/m-p/440428#M110007</guid>
      <dc:creator>Perreby</dc:creator>
      <dc:date>2018-02-27T10:14:00Z</dc:date>
    </item>
    <item>
      <title>Re: Appending dated tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-dated-tables/m-p/440431#M110009</link>
      <description>&lt;P&gt;Use a datastep to create the list of variables:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let currentmonth=201601;
%let previousyearmonth=201501;

data _null_;
length string $1000;
cur_month = input("&amp;amp;previousyearmonth.01",yymmdd8.);
do until (cur_month &amp;gt; input("&amp;amp;currentmonth.01",yymmdd8.));
  string = catx(' ',trim(string),'X_' !! put(cur_month,yymmn6.));
  cur_month = intnx('month',cur_month,1,'b');
end;
call symput('mydatasets',trim(string));
run;

data want;
set &amp;amp;mydatasets.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Feb 2018 10:18:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-dated-tables/m-p/440431#M110009</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-02-27T10:18:50Z</dc:date>
    </item>
    <item>
      <title>Re: Appending dated tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-dated-tables/m-p/440436#M110014</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;Why are the data stored like that?&amp;nbsp; From a storage point of view having multiple tables with similar data is inefficient - you have the extra overhead not only of the header block, but a read/write on each.&amp;nbsp; From a programming point of view it is inefficient - as you are finding now, trying to code with such a setup is a nightmare, creating masses of messy macro code.&amp;nbsp; Imagine how much simpler life would be if you stored all that data in one big dataset, with a column (you know those parts of the datasets used to capture data) for date, then your code would be as simple as:&lt;/P&gt;&lt;PRE&gt;data want;
  set have;
  where date between today() and intnx('month',today(),-1);
run;&lt;/PRE&gt;&lt;P&gt;Its your data modelling causing your issues - and most likely issues across the board.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sadly space and processing power is a problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We are talking about 100's of millions of records. So having it all in one big table makes it near impossible to statistical analysis on the data on a monthly basis let alone even more detailed disaggregated analysis on region, product, or day level&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So its broken up into smaller pieces (i.e monthly data).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But im busy developing an editing system to flag outlying data so need a proper time series (based on user inputs) and this lead me to this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2018 10:25:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-dated-tables/m-p/440436#M110014</guid>
      <dc:creator>Perreby</dc:creator>
      <dc:date>2018-02-27T10:25:00Z</dc:date>
    </item>
  </channel>
</rss>

