SAS Date Function INTNX( )

<< Go Back To SAS Date Functions

SAS INTNX( ) function is one of the important date functions in SAS.

INTNX() is basically used to get the future or back dated date with a gap of given specific intervals like MONTH, WEEK, YEAR etc.

In addition the date values can also be aligned to start, mid or end of given interval.

For example if you want to get the start and end dates of previous month then INTNX() is the best function to get it.

This has been demonstrated below;

1. SAS INTNX( ) function

SYNTAX: INTNX (interval, start_date, increment, alignment);

  • interval – it is time interval like MONTH, YEAR, QTR, WEEK etc. This should be enclosed in single quotes.

  • start-date – it is given date from which you want to navigate into future or past by given interval

  • increment – it is number of intervals you want to navigate in past or future. In case of past dates the number should be specified negative and for future dates it should be positive.

  • Alignment –‘B’ ‘E’ ‘M’ or ‘S’. It is optional argument which specifies alignment specific to given interval; e.g. in case of month ‘B’ gives 1st of the month, ‘M’ will give 15th of the month etc. By default it gives the same day.

Example: First and Last day of previous month using SAS INTNX( ) Function

SAS Code:

proc print data = temp;

run;

PROC PRINT OUTPUT :

data temp;

curr_date = "10Mar2010"d;

first_day_prev_month = intnx('month',curr_date,-1,'B');

last_day_prev_month = intnx('month',curr_date,-1,'E');

format curr_date first_day_prev_month last_day_prev_month date9.;

run;

* Please note this code has compiled on SAS 9.2 Platform.

Example: Finding a Date after 7 working days with INTNX ( ) function

data temp;

curr_date = "10Mar2010"d;

dt_after_7_wrking_days = intnx('WEEKDAY',curr_date,7);

format curr_date dt_after_7_wrking_days date9.;

run;

proc print data = temp;

run;

PROC PRINT OUTPUT:

Obs

1

curr_date

10MAR2010

dt_after_7_wrking_days

19MAR2010

* Please note this code has compiled on SAS 9.2 Platform.

If we see the code more closely;

The ‘interval’ used in the INTNX function above is ‘WEEKDAY’ which ignores Saturday and Sunday. Hence as 10th MAR was Wednesday; it ignored Week end on 13th and 14th and returned the date 19th Mar.

‘WEEKDAY1W’ is another option available in case if some one has only one weekly off with 6 working days.