<?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: Loop monthly tables and stack them in data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Loop-monthly-tables-and-stack-them-in-data-step/m-p/938088#M368525</link>
    <description>Thanks, Tom.&lt;BR /&gt;the scripts works with a %sysfunc() and the removal of quotes.</description>
    <pubDate>Fri, 02 Aug 2024 15:43:45 GMT</pubDate>
    <dc:creator>fwu811</dc:creator>
    <dc:date>2024-08-02T15:43:45Z</dc:date>
    <item>
      <title>Loop monthly tables and stack them in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-monthly-tables-and-stack-them-in-data-step/m-p/938072#M368519</link>
      <description>&lt;P&gt;Hi SAS Community users,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to loop a large number of historical data tables, and stack them into a single table using datastep.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, these tables named as comp_mmmyy, e.g., comp_jan24, comp_feb24,..., comp_jun24, and I am using the following code in EG:&lt;/P&gt;&lt;P&gt;%macro test;&lt;BR /&gt;data tmp;&lt;BR /&gt;set %do lp = &amp;amp;lp_min. %to &amp;amp;lp_max.; comp_&amp;amp;put(intnx("month","31dec1990"d,&amp;amp;lp.,"e"),monyy5.) %end;; run;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;%test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used to put function to convert a date format into mmmyy but got a warning for it, followed by errors in intnx().&lt;/P&gt;&lt;P&gt;Can you please let me where I am wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Aug 2024 14:41:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-monthly-tables-and-stack-them-in-data-step/m-p/938072#M368519</guid>
      <dc:creator>fwu811</dc:creator>
      <dc:date>2024-08-02T14:41:11Z</dc:date>
    </item>
    <item>
      <title>Re: Loop monthly tables and stack them in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-monthly-tables-and-stack-them-in-data-step/m-p/938077#M368520</link>
      <description>&lt;P&gt;To have the macro processor run a SAS function you need to nest the call in %SYSFUNC() macro function.&amp;nbsp; And you have to call PUTN() (or PUTC for character values) rather then PUT().&amp;nbsp; I assume because SAS found it was too hard to get %SYSFUNC() to work with PUT() and since the functionality is available with the other two function why bother.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you do not need to use the PUTN() function since you can pass the format to be applied to the result as the optional second argument to %SYSFUNC().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also there is no interval named "MONTH".&amp;nbsp; Do not add the quotes into the values of the strings you use in macro code.&amp;nbsp; Everything is a string to the macro processor.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%sysfunc(intnx(month,"31dec1990"d,&amp;amp;lp.,e),monyy5.) &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You might want to either assign the dataset name to a macro variable first or wrap the name in a %UNQUOTE() function call to make sure that the macro code does not confuse the parser into thinking you wanted two datasets named COMP_ and JAN24.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test;
%local lp dsname ;
data tmp;
  set 
%do lp = &amp;amp;lp_min. %to &amp;amp;lp_max.; 
  %let dsname=comp_%sysfunc(intnx(month,"31dec1990"d,&amp;amp;lp.,e),monyy5.) ;
  &amp;amp;dsname
%end;
  ; 
run;
%mend;

%test; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that it would work much better if the datasets where named COMP_202401 to COMP_202406.&amp;nbsp; Not only would the dataset names sort in chronological order but then you would not need any (or at least not as much) macro code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tmp;
   comp_202401 - comp_202406 ;
run;&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, 02 Aug 2024 15:00:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-monthly-tables-and-stack-them-in-data-step/m-p/938077#M368520</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-08-02T15:00:44Z</dc:date>
    </item>
    <item>
      <title>Re: Loop monthly tables and stack them in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-monthly-tables-and-stack-them-in-data-step/m-p/938082#M368522</link>
      <description>&lt;P&gt;If you want &lt;STRONG&gt;ALL&lt;/STRONG&gt; the data sets combined and do not have any others in the library whose names start with COMP_ this if very easy:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data tmp;
   set comp_: ;
run;&lt;/PRE&gt;
&lt;P&gt;The : immediately following part of the dataset name tells SAS to build a list of all names that start with the characters COMP_&lt;/P&gt;
&lt;P&gt;I would be tempted to add the INDSNAME option to capture the name of the data set that each record comes from:&lt;/P&gt;
&lt;PRE&gt;data tmp;
   set comp_:  indsname=dsn ;
   length dataset $ 41 ;
   dataset=dsn;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: If you use different naming practices such as COMP_YYYYMM where YYYY is a 4-digit year and MM is a 2-digit month with leading 0 as needed you could use such lists like&lt;/P&gt;
&lt;P&gt;Comp_2021: to get all the sets in year 2021&lt;/P&gt;
&lt;P&gt;Comp_202005 - Comp_202009 to get May through Sep .&lt;/P&gt;
&lt;P&gt;Also note that the typical file display programs would display these in chronological order.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Aug 2024 15:13:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-monthly-tables-and-stack-them-in-data-step/m-p/938082#M368522</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-08-02T15:13:30Z</dc:date>
    </item>
    <item>
      <title>Re: Loop monthly tables and stack them in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-monthly-tables-and-stack-them-in-data-step/m-p/938088#M368525</link>
      <description>Thanks, Tom.&lt;BR /&gt;the scripts works with a %sysfunc() and the removal of quotes.</description>
      <pubDate>Fri, 02 Aug 2024 15:43:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-monthly-tables-and-stack-them-in-data-step/m-p/938088#M368525</guid>
      <dc:creator>fwu811</dc:creator>
      <dc:date>2024-08-02T15:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: Loop monthly tables and stack them in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-monthly-tables-and-stack-them-in-data-step/m-p/938089#M368526</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to define the mmmyy range to consolidate the historical data, so the min and max of the loop need to be specified.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Aug 2024 15:45:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-monthly-tables-and-stack-them-in-data-step/m-p/938089#M368526</guid>
      <dc:creator>fwu811</dc:creator>
      <dc:date>2024-08-02T15:45:43Z</dc:date>
    </item>
    <item>
      <title>Re: Loop monthly tables and stack them in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Loop-monthly-tables-and-stack-them-in-data-step/m-p/938100#M368529</link>
      <description>&lt;P&gt;From more than two decades of experience in this job, and four decades in IT:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;NEVER&lt;/STRONG&gt; use 2-digit years.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;NEVER&lt;/STRONG&gt; use month names in filenames; use month numbers.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;ALWAYS&lt;/STRONG&gt; use a YMD order for dates; this sorts chronologically on its own, and makes the use of wildcards&amp;nbsp;&lt;EM&gt;much&lt;/EM&gt; easier.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Aug 2024 19:30:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Loop-monthly-tables-and-stack-them-in-data-step/m-p/938100#M368529</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-08-02T19:30:14Z</dc:date>
    </item>
  </channel>
</rss>

