I'm trying to find a shorter way of creating a range of macro variables with dates
the code I would usually use is below but I'm finding this is getting longer and longer as I'm now going back 12 months +
DATA _null_;
CALL SYMPUT('THIS_MONTH',PUT(INTNX('Month',today(),0,'b'),monyy.));
CALL SYMPUT('MONTH1',PUT(INTNX('Month',today(),-1,'b'),monyy.));
...
CALL SYMPUT('MONTH26',PUT(INTNX('Month',today(),-1,'b'),monyy.));
run;
%put &THIS_MONTH;
%put &MONTH1;
...
%put &MONTH26;
I was hoping that the same would be possible using a do loop... something along the lines of
data _null_;
do i=1 to i=5;
CALL SYMPUT('MONTH&i',PUT(INTNX('MONTH',today(),-&i.,'b'),monyy.));
end;
run;
%put &MONTH1;
%put &MONTH2;
the error I get in the log is
85 data _null_;
86 do i=1 to i=5;
87 CALL SYMPUT('MONTH&i',PUT(INTNX('MONTH',today(),-&i.,'b'),monyy.));
_
386
200
WARNING: Apparent symbolic reference I not resolved.
ERROR 386-185: Expecting an arithmetic expression.
ERROR 200-322: The symbol is not recognized and will be ignored.
Is this to do with the CALL SYMPUT executing before the 1st iteration of the do loop has completed and therefore not knowing the value of &i?
Alternative suggestions would be much appreciated
Thank you!