Hi Folks,
when using the GPLOT-Procedure, I can give a keyword like "YEAR" in order to have the axis values to loop on a yearly interval. Example:
PROC GPLOT DATA=book.graph1;
PLOT fund*date / VREF=5000 LV=1 CV=blue
HAXIS='01SEP1975'd TO '01SEP2015'd by YEAR;
FORMAT date mmddyy10.;
RUN;Now, I was wondering: does this functionality not also work with DO-LOOPs:
data _NULL_;
do k= intnx('month',today(),-13,'END') TO intnx('month',today(),-1,'END') by MONTH ;
put k=;
format k date9.;
end;
run;I get an Error message, however.
Is my syntax wrong, or does this functionality just not exist in the context of Loops?
What I would like to see in the Log is this:
k=31DEC2018
k=31JAN2019k=28FEB2019
k=31MAR2019...
...
...
Cheers,
FK
The BY specification (BY MONTH, or BY YEAR) is special syntax reserved for graphics procedures. However, you should be able to mimic that using:
data _NULL_;
do m = -13 to -1;
k= intnx('month',today(), m,'END');
put k=;
format k date9.;
end;
run;
The normal DO loop does not have all of functionality of the AXIS statements. (just like the macro %DO loop does not have all of the functionality of the data step DO loop).
You could just look over the offset.
data _null_;
do k= -13 to -1 ;
date=intnx('month',today(),k,'END') ;
put k= date= date9.;
end;
run;
Or add code to increment the variable and use WHILE or UNTIL to end the loop.
data _null_;
date=intnx('month',today(),-13,'END');
do until (date >= today());
put date= date9.;
date=intnx('month',date,1,'END') ;
end;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.