INTNX is a very useful SAS date function which returns a SAS date corresponding to a point within a time interval either in the past or the future. The general syntax of the INTNX function is:
Date_Variable = INTNX("interval",start_date,increment);
Intervals typically used with INTNX include WEEK, MONTH, QTR (quarter) and YEAR, and the function will return the start of the requested interval, e.g. weeks always begin on a Sunday and years on the 1st January.
It is not uncommon that the default starting points don't quite meet our needs. We can use a "shift index" in the interval specification to request an alternative starting point is used. For example the interval "WEEK.2" requests weeks which start on a Monday and "YEAR.11" requests years which start on the 1st November.
Here are a few examples using this technique:
data _null_; today = "10DEC2010"d; Next_Tuesday = INTNX("WEEK.3",today,1); Next_April_Fools = INTNX("YEAR.4",today,1);
put "The next Tuesday is: " Next_Tuesday date9.; put "The next April Fools Day is: " Next_April_Fools date9.; run;
The following is output to the SAS log:
The next Tuesday is: 14DEC2010 The next April Fools Day is: 01APR2011
For more information please consult the SAS Help documentation.