<?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: Fix statement %do YYMM=2306 %to 2403 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950282#M371628</link>
    <description>Work with dates, not with simple numbers.&lt;BR /&gt;Set the starting date, use a %DO %WHILE loop, and increment in the loop with %SYSFUNC(INTNX()). Use a YYMMN4. format to get the strings you want.</description>
    <pubDate>Sat, 09 Nov 2024 08:09:28 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2024-11-09T08:09:28Z</dc:date>
    <item>
      <title>Fix statement %do YYMM=2306 %to 2403</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950281#M371627</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;Let's say that&amp;nbsp; there are data sets :Mon_tbl_2301,Mon_tbl_2302,Mon_tbl_2303,...........and son on till&amp;nbsp;&amp;nbsp;Mon_tbl_2410&lt;/P&gt;
&lt;P&gt;As you can see the numbers in the name represent year and month in structure YYMM&lt;/P&gt;
&lt;P&gt;I know you don'y like it and you prefer YYYYMM&amp;nbsp; but These are the&amp;nbsp; data sets (I didn't choose the names of them).&lt;/P&gt;
&lt;P&gt;Let's say that I want to create one new data set that contain rows from data sets:&amp;nbsp; 2306 till 2403&lt;/P&gt;
&lt;P&gt;I want to do it using %DO loop&lt;/P&gt;
&lt;P&gt;What is the way to fix the statement-&amp;nbsp;%do YYMM=2306 %to 2403 ;&amp;nbsp; ???&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro RRR;
%do YYMM=2306  %to  2403 ;  
Data ttt;
set Mon_tbl&amp;amp;YYMM.;
Run;
proc append data=ttt base=want force;quit;
%end;
%mend;
%RRR
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Nov 2024 06:13:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950281#M371627</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-11-09T06:13:27Z</dc:date>
    </item>
    <item>
      <title>Re: Fix statement %do YYMM=2306 %to 2403</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950282#M371628</link>
      <description>Work with dates, not with simple numbers.&lt;BR /&gt;Set the starting date, use a %DO %WHILE loop, and increment in the loop with %SYSFUNC(INTNX()). Use a YYMMN4. format to get the strings you want.</description>
      <pubDate>Sat, 09 Nov 2024 08:09:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950282#M371628</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-11-09T08:09:28Z</dc:date>
    </item>
    <item>
      <title>Re: Fix statement %do YYMM=2306 %to 2403</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950285#M371629</link>
      <description>&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;The names of data sets are in format YYMM (It is not dates.....)&lt;/P&gt;
&lt;P&gt;What should be written instead of&amp;nbsp;&amp;nbsp;%do YYMM=2306 %to 2403?&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;I tried like that but It seems it is not working:&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;step1: Convert 2306 into sas date:&lt;/P&gt;
&lt;P&gt;INPUT( PUT(2306,Z4.),YYMMn4.)&lt;/P&gt;
&lt;P&gt;Step2:&lt;/P&gt;
&lt;P&gt;Go i months forward&amp;nbsp; (For example: one month forward)&lt;/P&gt;
&lt;P&gt;(%sysfunc(intnx(month, INPUT( PUT(2306,Z4.),YYMMn4.),+1,e)&lt;/P&gt;
&lt;P&gt;Step3:&lt;/P&gt;
&lt;P&gt;Convert date to numeric in form YYMM&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Input(%sysfunc(intnx(month, INPUT( PUT(2306,Z4.),YYMMn4.),+1,e)), yymmN4.);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Nov 2024 09:03:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950285#M371629</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-11-09T09:03:23Z</dc:date>
    </item>
    <item>
      <title>Re: Fix statement %do YYMM=2306 %to 2403</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950287#M371630</link>
      <description>&lt;P&gt;What is wrong with this code please?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;nbsp;&amp;nbsp;%sysfunc(inputn(%sysfunc(intnx(month ,%sysfunc(2306), yymmn4.), ),1,e),YYMMn4.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Nov 2024 09:18:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950287#M371630</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-11-09T09:18:42Z</dc:date>
    </item>
    <item>
      <title>Re: Fix statement %do YYMM=2306 %to 2403</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950288#M371631</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Work with dates, not with simple numbers.&lt;BR /&gt;Set the starting date, use a %DO %WHILE loop, and increment in the loop with %SYSFUNC(INTNX()). Use a YYMMN4. format to get the strings you want.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Can you please show the full code that run from 2306 till 2403 ?&lt;/P&gt;</description>
      <pubDate>Sat, 09 Nov 2024 09:20:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950288#M371631</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-11-09T09:20:28Z</dc:date>
    </item>
    <item>
      <title>Re: Fix statement %do YYMM=2306 %to 2403</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950289#M371632</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;What is wrong with this code please?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;nbsp;&amp;nbsp;%sysfunc(inputn(%sysfunc(intnx(month ,%sysfunc(2306), yymmn4.), ),1,e),YYMMn4.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;%SYSFUNC expects a data step function as its first argument. 2306 is not a data step function.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Nov 2024 10:05:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950289#M371632</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-11-09T10:05:58Z</dc:date>
    </item>
    <item>
      <title>Re: Fix statement %do YYMM=2306 %to 2403</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950290#M371633</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro rrr(start,end);
/* start and end are supplied in YYMM format */
/* feed input data via parameters, not by "something which exists somewhere";
   always include a comment describing the parameters */
%local month yymm;
/* prevent unwanted side effects if the variables exist in an outside context;
   has to be part of any proper macro code */
%let month = %sysfunc(inputn(&amp;amp;start.,yymmn4.));
%do %while (&amp;amp;month. le %sysfunc(inputn(&amp;amp;end.,yymmn4.)));
  %let yymm = %sysfunc(putn(&amp;amp;month.,yymmn4.));
  /* your loop code comes here, using yymm */
  %let month = %sysfunc(intnx(month;&amp;amp;month.,1,b));
%end;
%mend rrr;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 10 Nov 2024 18:26:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950290#M371633</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-11-10T18:26:01Z</dc:date>
    </item>
    <item>
      <title>Re: Fix statement %do YYMM=2306 %to 2403</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950292#M371634</link>
      <description>&lt;P&gt;Do you really need a macro loop? If there aren't any tables with the same root name but yymmdd naming patterns in the same library then a simple data step would likely do as well.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* option 1 */
data want;
  set mon_tbl2306 - mon_tbl2403;
run;

/* option 2 */
%macro RRR(start_mth, stop_mth);
  proc datasets lib=work nolist nowarn;
    delete want;
  quit;

  %local mth;
  %let mth=&amp;amp;start_mth;
  %do %until(&amp;amp;mth&amp;gt;&amp;amp;stop_mth);
    proc append data=mon_tbl&amp;amp;mth base=work.want force;
    quit; 
    %let mth=%sysfunc(intnx(month,%sysfunc(inputn(&amp;amp;mth, yymmn4.)),1,b),yymmn4.);
  %end;
%mend;
%RRR(2306, 2403);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Nov 2024 11:37:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950292#M371634</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-11-09T11:37:37Z</dc:date>
    </item>
    <item>
      <title>Re: Fix statement %do YYMM=2306 %to 2403</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950293#M371635</link>
      <description>&lt;P&gt;Don't do a loop.&amp;nbsp; Do a list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming that your library only has monthly datasets with the name structure you provided, then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let yymm_beg=2306;
%let yymm_end=2403;

/* Make a list of dataset names */
proc sql noprint;
  select distinct memname into :dsnlist separated by ' '
  from dictionary.members where
  libname='WORK' and memname&amp;gt;="MON_TBL&amp;amp;yymm_beg" and memname&amp;lt;="MON_TBL&amp;amp;yymm_end";
quit;

%put &amp;amp;=dsnlist;

/* Convert the last of datasets into a single data set view */
data need/ view=need;
  set &amp;amp;dsnlist open=defer;
run;

/* Invoke proc append only once - append the view of concatenated datasets */
proc append data=need base=want force;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The "open=defer" tells SAS to only generate one dataset input buffer, to be repeatedly used for each of the SET datasets.&amp;nbsp; Saves memory, but will make the result contain only the variables in the first dataset in the list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Nov 2024 13:07:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950293#M371635</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-11-09T13:07:00Z</dc:date>
    </item>
    <item>
      <title>Re: Fix statement %do YYMM=2306 %to 2403</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950294#M371636</link>
      <description>&lt;P&gt;Just iterate over the number of months.&amp;nbsp; You can then use INTNX() function to generate the actual month strings from the index number.&amp;nbsp; You can use INTCK() function to calculate how many months you want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro RRR;
%local offset yymm start;
%let start = '01JUN2023'd;
%do offset=0 %to %sysfunc(intck(month,&amp;amp;start,'01MAR2024'd));
  %let yymm=%sysfunc(intnx(month,&amp;amp;start,&amp;amp;offset),yymmn4.);
proc append base=want data=mon_tbl&amp;amp;YYMM. force;
quit;
%end;
%mend;
%RRR&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Nov 2024 13:26:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950294#M371636</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-11-09T13:26:55Z</dc:date>
    </item>
    <item>
      <title>Re: Fix statement %do YYMM=2306 %to 2403</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950295#M371637</link>
      <description>&lt;P&gt;As you can see, this has the possibility of being a complex problem.&amp;nbsp; At the cost of some processing time, let me show you how to turn it into an easy problem, one that most junior programmers would use and maintain.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro RRR;
   %local month.
   %do YYMM=2306  %to  2403 ;  
      %let month = %substr(&amp;amp;YYMM, 3, 2);
      %if &amp;amp;month &amp;gt; 0 and &amp;amp;month &amp;lt; 13 %then %do;
         Data ttt;
         set Mon_tbl&amp;amp;YYMM.;
         run;
         proc append data=ttt base=want force;quit;
      %end;
   %end;
%mend;
%RRR&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So you go through 100 iterations of a %DO loop, and only process the values that represent a valid month.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Nov 2024 13:29:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950295#M371637</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2024-11-09T13:29:00Z</dc:date>
    </item>
    <item>
      <title>Re: Fix statement %do YYMM=2306 %to 2403</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950297#M371638</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;Let's say that&amp;nbsp; there are data sets :Mon_tbl_2301,Mon_tbl_2302,Mon_tbl_2303,...........and son on till&amp;nbsp;&amp;nbsp;Mon_tbl_2410&lt;/P&gt;
&lt;P&gt;As you can see the numbers in the name represent year and month in structure YYMM&lt;/P&gt;
&lt;P&gt;I know you don'y like it and you prefer YYYYMM&amp;nbsp; but These are the&amp;nbsp; data sets (I didn't choose the names of them).&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Always work with actual SAS dates, formatted in whatever way is appropriate for your problem. As soon as you have a problem that involves calendar issues, work with actual SAS dates. The reason &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; and I and many others advise you to always work with SAS dates is because SAS already knows that the month after 2312 is 2401. You don't have to program that yourself. As long as you have a true SAS date value (formatted as YYMM or any other date format or even unformatted), and use the proper SAS functions, you benefit from all the work that SAS has done in handling dates and months and years. Anyway, Kurt has provided a solution which works with dates, rather than trying to achieve this by other methods which the programmer would then have to program from scratch.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Nov 2024 14:06:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950297#M371638</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-11-09T14:06:43Z</dc:date>
    </item>
    <item>
      <title>Re: Fix statement %do YYMM=2306 %to 2403</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950301#M371639</link>
      <description>&lt;P&gt;Agree with others, that code is usually simpler and more readable if you use SAS date values.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case, if you pass in a SAS date for start and end, then you can increment by month within the loop using INTNX.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note I had to add 1 to &amp;amp;end, because the macro compiler won't let you use %BY 0 for fear of an infinite loop.&amp;nbsp; This could also be done as a %DO %WHILE or %DO %UNTIL, if that hack is unappealing to you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro foo(start,end) ;
  %local date ;
  %do date=%sysevalf(&amp;amp;start) %to %sysevalf(&amp;amp;end+1); %*Add a day to end because do-loop will increment by 1;

    %put %sysfunc(putn(&amp;amp;date,yymmn6)) ;

    %let date=%sysfunc(intnx(month,&amp;amp;date,1)) ;
  %end ;
%mend foo ;

%foo("01Jun2023"d,"01Mar2024"d)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Nov 2024 17:32:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950301#M371639</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-11-09T17:32:41Z</dc:date>
    </item>
    <item>
      <title>Re: Fix statement %do YYMM=2306 %to 2403</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950302#M371640</link>
      <description>&lt;P&gt;Unlike much of the advice you have been given on this topic, from experienced and thoughtful respondents, in this instance I do not subscribe to the "always use date values" in the naming of your monthly datasets.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have already recommended generating a list of datasets, concatenated into a dataset view, and appended once, which I think is likely more efficient.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if you MUST generate macro loop replicating a sequence of months in a YYMM expression, it is straightforward.&amp;nbsp; I have frequently used the approach below, which has a major loop of YY over years, then a minor loop of MM over months.&amp;nbsp; The month loop goes from 1 to 12, unless it is part of the first or last year:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro rrr (yymm_beg=,yymm_end=);
  %do yy=%substr(&amp;amp;yymm_beg,1,2) %to %substr(&amp;amp;yymm_end,1,2);
    %let mm_beg= %sysfunc(ifn(&amp;amp;yy=%substr(&amp;amp;yymm_beg,1,2),%substr(&amp;amp;yymm_beg,3,2),1));
    %let mm_end= %sysfunc(ifn(&amp;amp;yy=%substr(&amp;amp;yymm_end,1,2),%substr(&amp;amp;yymm_end,3,2),12));

    %do mm=&amp;amp;mm_beg %to &amp;amp;mm_end;
      %let mm=%sysfunc(putn(&amp;amp;mm,z2.));  /*Insert leading zero*/
      proc append data=Mon_tbl&amp;amp;yy&amp;amp;mm  base=want force;
      run;
    %end;
  %end;
%mend;

%rrr(yymm_beg=2306,yymm_end=2403);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Nov 2024 17:34:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950302#M371640</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-11-09T17:34:00Z</dc:date>
    </item>
    <item>
      <title>Re: Fix statement %do YYMM=2306 %to 2403</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950303#M371641</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't see how your code accounts for the fact the the month after 2312 is 2401&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But anyway, the code you use of pulling apart strings uses logic that is not as straightforward as having SAS figure out what is the next month after a given month. This is much simpler to understand and IMHO much simpler to program.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Nov 2024 17:43:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950303#M371641</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-11-09T17:43:36Z</dc:date>
    </item>
    <item>
      <title>Re: Fix statement %do YYMM=2306 %to 2403</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950304#M371642</link>
      <description>&lt;P&gt;That works well for MONTH intervals if for some reason you did not have access to functions that know how to handle dates.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I wouldn't hide simple IF/THEN logic in the middle of a function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    %let mm_beg=1;
    %let mm_end=12;
    %if &amp;amp;yy=%substr(&amp;amp;yymm_beg,1,2) %then %let mm_beg=%substr(&amp;amp;yymm_beg,3,2);
    %if &amp;amp;yy=%substr(&amp;amp;yymm_end,1,2) %then %let mm_end=%substr(&amp;amp;yymm_end,3,2);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But since your code is already using %SYSFUNC() to call SAS functions why not just use INPUTN(), INTCK() and INTNX()?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro rrr(yymm_beg=,yymm_end=);
  %local beg_date end_date offset yymm ;
  %let beg_date=%sysfunc(inputn(&amp;amp;yymm_beg,yymmn4.));
  %let end_date=%sysfunc(inputn(&amp;amp;yymm_end,yymmn4.));
  %do offset=0 %to %sysfunc(intck(month,&amp;amp;beg_date,&amp;amp;end_date));
    %let yymm=%sysfunc(intnx(month,&amp;amp;beg_date,&amp;amp;offset),yymmn4.);
    %put yymm=&amp;amp;yymm;
/*
proc append data=Mon_tbl&amp;amp;yymm base=want force;
run;
*/
  %end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which has the added advantage that the same basic code structure can be used to iterate by almost any other DATE, TIME or DATETIME interval.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Nov 2024 17:59:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950304#M371642</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-11-09T17:59:00Z</dc:date>
    </item>
    <item>
      <title>Re: Fix statement %do YYMM=2306 %to 2403</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950305#M371643</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't see how your code accounts for the fact the the month after 2312 is 2401&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is accounted for in constructing macrovar MM_BEG, which is done once for each year.&amp;nbsp;&amp;nbsp;Similarly once per year, the macro MM_END is constructed.&amp;nbsp; If you run the macro below, you'll see the proper sequence of 2312 followed by 2401:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro rrr (yymm_beg=,yymm_end=);
  %do yy=%substr(&amp;amp;yymm_beg,1,2) %to %substr(&amp;amp;yymm_end,1,2);
    %put &amp;amp;=yy ;
    %let mm_beg= %sysfunc(ifn(&amp;amp;yy=%substr(&amp;amp;yymm_beg,1,2),%substr(&amp;amp;yymm_beg,3,2),01));
    %let mm_end= %sysfunc(ifn(&amp;amp;yy=%substr(&amp;amp;yymm_end,1,2),%substr(&amp;amp;yymm_end,3,2),12));

    %do mm=&amp;amp;mm_beg %to &amp;amp;mm_end;
      %let mm=%sysfunc(putn(&amp;amp;mm,z2.));  /*Insert leading zero*/
      %put %str(   ) YYMM becomes &amp;amp;yy&amp;amp;mm;
    %end;
  %end;
%mend;
%rrr(yymm_beg=2306,yymm_end=2403);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;also wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But anyway, the code you use of pulling apart strings uses logic that is not as straightforward as having SAS figure out what is the next month after a given month. This is much simpler to understand and IMHO much simpler to program.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;After thinking about your comment, I realized I had forgotten about %DO %WHILE, which I find to be an easier way to use sas date capacities than iterative&amp;nbsp; %DO, and it avoids the need to generate leading zeroes for MM=1 through 9.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro rrr(yymm_beg=,yymm_end=);

  %let yymm=&amp;amp;yymm_beg;
  %let date= %sysfunc(inputn(&amp;amp;yymm.01,yymmdd6.));

  %do %while (&amp;amp;yymm &amp;lt;= &amp;amp;yymm_end);
    %put &amp;amp;=yymm;   /*User code here */
    %let date = %sysfunc(intnx(month,&amp;amp;date,1));
    %let YYMM=%sysfunc(putn(&amp;amp;date,YYMMN4.));
  %end;
%mend rrr;

%rrr(yymm_beg=2306,yymm_end=2403);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Nov 2024 19:10:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950305#M371643</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-11-09T19:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: Fix statement %do YYMM=2306 %to 2403</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950306#M371644</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro rrr(yymm_beg=,yymm_end=);

  %let yymm=&amp;amp;yymm_beg;
  %let date= %sysfunc(inputn(&amp;amp;yymm.01,yymmdd6.));

  %do %while (&amp;amp;yymm &amp;lt;= &amp;amp;yymm_end);
    %put &amp;amp;=yymm;   /*User code here */
    %let date = %sysfunc(intnx(month,&amp;amp;date,1));
    %let YYMM=%sysfunc(putn(&amp;amp;date,YYMMN4.));
  %end;
%mend rrr;

%rrr(yymm_beg=2306,yymm_end=2403);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I like this solution very much.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Nov 2024 19:48:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950306#M371644</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-11-09T19:48:01Z</dc:date>
    </item>
    <item>
      <title>Re: Fix statement %do YYMM=2306 %to 2403</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950307#M371645</link>
      <description>&lt;P&gt;Make your macro variables local, or you'll have a rude awakening if someone uses yymm or date as macro variables in the calling context.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Nov 2024 20:00:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950307#M371645</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-11-09T20:00:50Z</dc:date>
    </item>
    <item>
      <title>Re: Fix statement %do YYMM=2306 %to 2403</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950308#M371646</link>
      <description>&lt;P&gt;Never much like to use looping that requires the user to increment the counter on their own.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Especially for a situation where the number of loops that are needed is know (or easily calculated as in this case).&lt;/P&gt;</description>
      <pubDate>Sat, 09 Nov 2024 23:17:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fix-statement-do-YYMM-2306-to-2403/m-p/950308#M371646</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-11-09T23:17:06Z</dc:date>
    </item>
  </channel>
</rss>

