@PaigeMiller wrote:
@mkeintz
I don't see how your code accounts for the fact the the month after 2312 is 2401
That is accounted for in constructing macrovar MM_BEG, which is done once for each year. Similarly once per year, the macro MM_END is constructed. If you run the macro below, you'll see the proper sequence of 2312 followed by 2401:
%macro rrr (yymm_beg=,yymm_end=);
%do yy=%substr(&yymm_beg,1,2) %to %substr(&yymm_end,1,2);
%put &=yy ;
%let mm_beg= %sysfunc(ifn(&yy=%substr(&yymm_beg,1,2),%substr(&yymm_beg,3,2),01));
%let mm_end= %sysfunc(ifn(&yy=%substr(&yymm_end,1,2),%substr(&yymm_end,3,2),12));
%do mm=&mm_beg %to &mm_end;
%let mm=%sysfunc(putn(&mm,z2.)); /*Insert leading zero*/
%put %str( ) YYMM becomes &yy&mm;
%end;
%end;
%mend;
%rrr(yymm_beg=2306,yymm_end=2403);
@PaigeMiller also wrote:
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.
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 %DO, and it avoids the need to generate leading zeroes for MM=1 through 9.
%macro rrr(yymm_beg=,yymm_end=);
%let yymm=&yymm_beg;
%let date= %sysfunc(inputn(&yymm.01,yymmdd6.));
%do %while (&yymm <= &yymm_end);
%put &=yymm; /*User code here */
%let date = %sysfunc(intnx(month,&date,1));
%let YYMM=%sysfunc(putn(&date,YYMMN4.));
%end;
%mend rrr;
%rrr(yymm_beg=2306,yymm_end=2403);
... View more