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;

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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