Another very important Date function : INTNX

Change the date

SAS is full of date related function and we will try to cover most used and important functions at Ask Analytics sooner or later. We have already covered INTCK function, which helps identify the gap in between two dates on various scales. Let's now understand its sister function INTNX, which is used for the date progression.

It would help answer, "when is our next date?"


The syntax of INTNX is :


 Period = INTNX ( Interval, start date, shift, alignment); 

Better we learn with examples:


Data learn_intnx;
input base_date date9. ;
year_1 = intnx('year',base_date , 1,'b');                          /* Line A */
year_2 = intnx('year',base_date , 1,'m');                        /* Line B */
year_3 = intnx('year',base_date , 1,'e');                        /* Line C */
year_4 = intnx('year',base_date , 1,'s');                        /* Line D */
month_1 = intnx('month',base_date , 1,'b');
month_2 = intnx('month',base_date , 1,'m');
month_3 = intnx('month',base_date , 1,'e');
month_4 = intnx('month',base_date , 1,'s');
week_1 = intnx('week',base_date , 1,'b');
week_2 = intnx('week',base_date , 1,'m');
week_3 = intnx('week',base_date , 1,'e');
week_4 = intnx('week',base_date , 1,'s');
format base_date year: month: week: date9.;
cards;
2apr2015
;
proc print;

run;

Please run the above code and check the result and you would understand, how it works.

Line A: We have shifted the date 2nd April 2015 one year and have asked SAS to return the beginning of year (using b as alignment) and hence it give 1st Jan 2016.
Line B: Rest remaining same we have now asked SAS to return the middle date of (using m as alignment) and hence it give 1st Jul 2016.


Line C: Now end date of (using e as alignment) and hence it give 31st Dec 2016.

Line D: Alignment s stands for SAMEDAY, which was added quite late in SAS; earlier versions don't have it. It maintains the day part of date while shifting it and hence gives 02nd Apr 2016.

We can shift the date both forward and backward, just use a negative value in shift argument.

The function is extensively used in Banking and Insurance industry (as far as I have observed), hope you would find the explanation of the function quite useful.

There are many other intervals that can be used, we have just demonstrated most used one.

Enjoy reading our other articles and stay tuned with us.


Kindly do provide your feedback in the 'Comments' Section and share as much as possible.