<?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: Arrays and Variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Arrays-and-Variable/m-p/46648#M9627</link>
    <description>Hi Spud&lt;BR /&gt;
&lt;BR /&gt;
Here 3 variants how you could do it. I prefer variant 3 with the view.&lt;BR /&gt;
Variant 2 creates a physical table but at least doesn't process all the daily tables all the time; but: it aborts with an error if there is no new daily table for a specific rundate.&lt;BR /&gt;
&lt;BR /&gt;
Variant 1 works also but passes all the daily tables with every run. This is not the most efficient way to do things - and your job will take longer and longer the more you come to the end of a month (that's also true for variant 2).&lt;BR /&gt;
&lt;BR /&gt;
Variant 3 builds only a view. This is very fast, runs at the end of the month almost as fast as at the beginning and doesnt' duplicate data (storage).&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick&lt;BR /&gt;
&lt;BR /&gt;
/* Create some test tables */&lt;BR /&gt;
data work.Tab20080801 work.Tab20080901 work.Tab20080902 work.Tab20080903 work.Tab20080904 work.Tab20080906 &lt;BR /&gt;
     work.Tab%sysfunc(today(),yymmddN8.)  work.Tab20081020;&lt;BR /&gt;
  var='some value';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* Get the date for which tables have to be selected */&lt;BR /&gt;
%let DateKey=%sysfunc(today());&lt;BR /&gt;
&lt;BR /&gt;
/*******&lt;BR /&gt;
If a run on the first day of a new month has to pick the tables from the &lt;BR /&gt;
previous month then use this one:&lt;BR /&gt;
%let DateKey=%eval(%sysfunc(today())-1);&lt;BR /&gt;
*******/&lt;BR /&gt;
&lt;BR /&gt;
/* select all Tablenames from the current month */&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
    select memname into :MonthTblList separated by ' '&lt;BR /&gt;
     from dictionary.members&lt;BR /&gt;
      where libname='WORK' and memname like "TAB%sysfunc(putn(&amp;amp;datekey,yymmN6.))%%"&lt;BR /&gt;
      order by memname;&lt;BR /&gt;
    %put MonthTblList;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
/* variant 1:                                               */&lt;BR /&gt;
/* create the month table physically everytime from scratch */&lt;BR /&gt;
data MonthTab%sysfunc(putn(&amp;amp;datekey,yymmN6.));&lt;BR /&gt;
  set &amp;amp;MonthTblList;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* variant 2:                                               */&lt;BR /&gt;
/* add only the latest day table to the month table         */&lt;BR /&gt;
proc append base=MonthTab%sysfunc(putn(&amp;amp;datekey,yymmN6.))&lt;BR /&gt;
            data=Tab%sysfunc(putn(&amp;amp;datekey,yymmddN8.))&lt;BR /&gt;
  force;&lt;BR /&gt;
quit;run;&lt;BR /&gt;
&lt;BR /&gt;
/* variant 3:                                                 */&lt;BR /&gt;
/* create a monthly view for all existing tables of a month   */&lt;BR /&gt;
data VMonthTab%sysfunc(putn(&amp;amp;datekey,yymmN6.)) / view=VMonthTab%sysfunc(putn(&amp;amp;datekey,yymmN6.));&lt;BR /&gt;
  set &amp;amp;MonthTblList;&lt;BR /&gt;
run;

Message was edited by: Patrick</description>
    <pubDate>Sat, 20 Sep 2008 09:41:13 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2008-09-20T09:41:13Z</dc:date>
    <item>
      <title>Arrays and Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays-and-Variable/m-p/46646#M9625</link>
      <description>Hi&lt;BR /&gt;
&lt;BR /&gt;
I have daily tables and i want to produce an up2date monthly table.&lt;BR /&gt;
so my table names are tab20080901, tab20080902, up to tab20080915(being yesterday).&lt;BR /&gt;
so i would like to combine these to produce a table tab200809.&lt;BR /&gt;
But if i run this tomorrow i would like to, obviously, include tab20080916.&lt;BR /&gt;
so it needs to know what month and day it, and then combine all necessary tables.&lt;BR /&gt;
I've been told this is probably a job for Array man!!&lt;BR /&gt;
&lt;BR /&gt;
Any ideas?&lt;BR /&gt;
&lt;BR /&gt;
Si</description>
      <pubDate>Tue, 16 Sep 2008 15:11:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays-and-Variable/m-p/46646#M9625</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-09-16T15:11:39Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays and Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays-and-Variable/m-p/46647#M9626</link>
      <description>You can either choose a SAS macro language approach or a use a SAS DATA step, in order to generate the SAS execution code each day inline for your purpose.&lt;BR /&gt;
&lt;BR /&gt;
A DATA step approach would involve using the INTNX function to step through each date, building SAS code with PUT statements, out to a "temp" sequential file allocation, and then use %INCLUDE to run your "generated" SAS code.&lt;BR /&gt;
&lt;BR /&gt;
An example:&lt;BR /&gt;
&lt;BR /&gt;
FILENAME TEMPSAS TEMP;&lt;BR /&gt;
DATA _NULL_;&lt;BR /&gt;
FILE TEMPSAS;&lt;BR /&gt;
MSTARTDT = INTNX('MONTH',TODAY(),0);&lt;BR /&gt;
PUT 'DATA tab' MSTARTDT YYMMN6. ';';&lt;BR /&gt;
PUT 'SET' @;&lt;BR /&gt;
DO MYDATE=MSTARTDT TO TODAY()-1;&lt;BR /&gt;
   PUT ' tab' MYDATE YYMMDDN8. @;&lt;BR /&gt;
END;&lt;BR /&gt;
PUT '; ' / 'RUN;';&lt;BR /&gt;
RUN;&lt;BR /&gt;
%INCLUDE TEMPSAS;&lt;BR /&gt;
&lt;BR /&gt;
Some similar macro language logic would also apply, except there is no need to send the SAS code to an external file -- it would be compiled by SAS and then executed.&lt;BR /&gt;
&lt;BR /&gt;
Hope that helps.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Tue, 16 Sep 2008 15:52:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays-and-Variable/m-p/46647#M9626</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2008-09-16T15:52:16Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays and Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays-and-Variable/m-p/46648#M9627</link>
      <description>Hi Spud&lt;BR /&gt;
&lt;BR /&gt;
Here 3 variants how you could do it. I prefer variant 3 with the view.&lt;BR /&gt;
Variant 2 creates a physical table but at least doesn't process all the daily tables all the time; but: it aborts with an error if there is no new daily table for a specific rundate.&lt;BR /&gt;
&lt;BR /&gt;
Variant 1 works also but passes all the daily tables with every run. This is not the most efficient way to do things - and your job will take longer and longer the more you come to the end of a month (that's also true for variant 2).&lt;BR /&gt;
&lt;BR /&gt;
Variant 3 builds only a view. This is very fast, runs at the end of the month almost as fast as at the beginning and doesnt' duplicate data (storage).&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick&lt;BR /&gt;
&lt;BR /&gt;
/* Create some test tables */&lt;BR /&gt;
data work.Tab20080801 work.Tab20080901 work.Tab20080902 work.Tab20080903 work.Tab20080904 work.Tab20080906 &lt;BR /&gt;
     work.Tab%sysfunc(today(),yymmddN8.)  work.Tab20081020;&lt;BR /&gt;
  var='some value';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* Get the date for which tables have to be selected */&lt;BR /&gt;
%let DateKey=%sysfunc(today());&lt;BR /&gt;
&lt;BR /&gt;
/*******&lt;BR /&gt;
If a run on the first day of a new month has to pick the tables from the &lt;BR /&gt;
previous month then use this one:&lt;BR /&gt;
%let DateKey=%eval(%sysfunc(today())-1);&lt;BR /&gt;
*******/&lt;BR /&gt;
&lt;BR /&gt;
/* select all Tablenames from the current month */&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
    select memname into :MonthTblList separated by ' '&lt;BR /&gt;
     from dictionary.members&lt;BR /&gt;
      where libname='WORK' and memname like "TAB%sysfunc(putn(&amp;amp;datekey,yymmN6.))%%"&lt;BR /&gt;
      order by memname;&lt;BR /&gt;
    %put MonthTblList;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
/* variant 1:                                               */&lt;BR /&gt;
/* create the month table physically everytime from scratch */&lt;BR /&gt;
data MonthTab%sysfunc(putn(&amp;amp;datekey,yymmN6.));&lt;BR /&gt;
  set &amp;amp;MonthTblList;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* variant 2:                                               */&lt;BR /&gt;
/* add only the latest day table to the month table         */&lt;BR /&gt;
proc append base=MonthTab%sysfunc(putn(&amp;amp;datekey,yymmN6.))&lt;BR /&gt;
            data=Tab%sysfunc(putn(&amp;amp;datekey,yymmddN8.))&lt;BR /&gt;
  force;&lt;BR /&gt;
quit;run;&lt;BR /&gt;
&lt;BR /&gt;
/* variant 3:                                                 */&lt;BR /&gt;
/* create a monthly view for all existing tables of a month   */&lt;BR /&gt;
data VMonthTab%sysfunc(putn(&amp;amp;datekey,yymmN6.)) / view=VMonthTab%sysfunc(putn(&amp;amp;datekey,yymmN6.));&lt;BR /&gt;
  set &amp;amp;MonthTblList;&lt;BR /&gt;
run;

Message was edited by: Patrick</description>
      <pubDate>Sat, 20 Sep 2008 09:41:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays-and-Variable/m-p/46648#M9627</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2008-09-20T09:41:13Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays and Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays-and-Variable/m-p/46649#M9628</link>
      <description>Thanks patrick and sbb</description>
      <pubDate>Tue, 23 Sep 2008 10:27:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays-and-Variable/m-p/46649#M9628</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-09-23T10:27:13Z</dc:date>
    </item>
  </channel>
</rss>

