Site hosted by Angelfire.com: Build your free website today!
SAS(r) Software Tips
Using Variable Intervals For INTNX Function
INTNX is a very powerful function. Since enhancements were made in Release 607 (documented in P222, Changes & Enhancements For Release 607) this function became even more powerful. However, its power increased manyfold again when I discovered the apparently undocumented fact that the interval can be a variable value.

In this example I wish to determine the week day 7 days ago. By default, INTNX will return the start of the week, so I would normally get the first day of the week. By using the 607 and onwards parameter that permits shifting from the period start to a point within, I can easily acheive my objective:

data test ;
date = today(); /* today is Tuesday day 3 in SAS terms */
newdate = intnx('week.3',date,-1) ;
put date= date9. newdate= date9. ;
run ;

However, I had to hardcode the shift parameter -- 3 above. I general I would rather not do that as I do not know the shift in advance. But using a variable value for the interval permits the problem to be easily solved:

data test ;
date = today() ; 
weekday = put(weekday(date),1.) ;
newdate = intnx('week.' !! weekday,date,-1) ;
put date= date9. newdate= date9. ;
run ;

Contact Don Stanley