BookmarkSubscribeRSS Feed
FK1
Lapis Lazuli | Level 10 FK1
Lapis Lazuli | Level 10

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=31JAN2019

k=28FEB2019
k=31MAR2019

...

...

...

Cheers,

FK

2 REPLIES 2
Astounding
PROC Star

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;
Tom
Super User Tom
Super User

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;

 

 

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 950 views
  • 0 likes
  • 3 in conversation