Advanced Date function : INTCK

INTCK is a very useful function that returns the number of intervals between two dates. Intervals can be in terms of WEEK, MONTH, QUARTER or YEAR etc.

There are other variation also possible in period calculations with this function.

So let's explore about the same in detail.


The syntax of INTCK is :


 Period = INTCK (interval<multiples><shift> ,  start_date ,  end_date, method); 

Better we learn with examples:


Let's start with only basic arguments : Interval, Start_date and End_date.

Data Learn_INTCK;
period_1 = INTCK('WEEK','16AUG2002'd,'24AUG2002'd);
period_2 = INTCK('YEAR', '01JAN2002'd,'31DEC2002'd);
period_3 = INTCK('YEAR', '01JAN2002'd,'30Nov2003'd);
Period_4 = INTCK('QTR','01JAN2002'd,'01AUG2002'd);
Period_5 = INTCK('QTR','01JAN2002'd,'30Sep2002'd);
Period_6 = INTCK('MONTH','01JAN2002'd,'15AUG2002'd);
Period_7 = INTCK('MONTH','01JAN2002'd,'30Sep2002'd);
Proc Print;

Run;




Do try various versions of the code with different dates. It is worth to note that INTCK gives the time intervals passed between two dates as per the calendar. To be more clear on this, let's take an example of  ‘YEAR’ interval, for any two dates within the same calendar year will return 0; but       31 DEC 2010 and its next day 01 JAN 2011 will return 1, moreover 01 JAN 2010 and 31 DEC 2011 will also return 1.

Data difference ;
A = INTCK('YEAR', "31Dec2014"d, "01JAN2015"d);                       /* Gives 1 */
B = INTCK('YEAR', "01Jan2014"d, "31Dec2014"d);                         /* Gives 0 */
C = INTCK('YEAR', "01Jan2014"d, "01Jan2015"d);                          /* Gives 1 */
Proc Print;
Run;

Strange ! Right  ?? Yes it is, but that's how it is. So please be very careful.

Basically INTCK by default considers the discrete form of calculations. It check that year has changes so gives change in year. If year is same ( as in B's case), it gives 0.

But suppose we want to change the calculations from default discrete method to continuous method, we can use the 4th argument : method.

Use 'c' for making calculations continuous, 'd' for discrete ( as such default is discrete itself).


Data difference_with_C ;
A = INTCK('YEAR', "31Dec2014"d, "01JAN2015"d, 'c' );                   /* Gives 0 */
B = INTCK('YEAR', "01Jan2014"d, "31Dec2014"d, 'c' );                     /* Gives 0 */
C = INTCK('YEAR', "01Jan2014"d, "01Jan2015"d, 'c' );                      /* Gives 1 */
Proc Print;
Run;

 Hope you now got the contrast. In B however, it has still given 0 .... Why ?
Happy B'Date Aarya




My daughter Aarya was born on 26th Nov,2014, she completed her one year on 26th Nov,2015 not on 25th; that's the idea behind celebrating B'Dates and anniversaries on the same day of every year. This blog is my gift on her B'Date (belated) !


Also try :

Data Happy_Bday ;
A = INTCK('YEAR', "26Nov2014"d, "25Nov015"d,'c');                       /* Gives 0 */
B = INTCK('YEAR', "26Nov2014"d, "26Nov015"d,'c');                       /* Gives 1 */
Proc Print;
Run;


Let's now understand the use of sub-arguments of "Interval" : 



Shift :

With use of shift you can change the starting month of the year e.g. YEAR.2 specifies yearly periods shifted to start on the first of Feb of each calendar year and to end in January of the following year.


Data temp;
A=       Intck('Year', "01Feb2010"d, "01Jan2012"d);                     /* Gives 2 */
B =      Intck('Year.2', "01Feb2010"d, "01Jan2012"d);                  /* Gives 1 */
C =      Intck('Year.2', "01Feb2010"d, "01Feb2012"d);                  /* Gives 2 */
Proc Print;

Run;

In B it gives 1, as year is starting with Feb now instead of default Jan and will finish with Jan end of next year.

Multiple :


You can add sub-argument to interval called "Multiples", with which you can calculate the number of period such as 2 Weeks, 3 Months etc.:

Data with_Shift;
two_weeks = Intck('Week2', "01Jan2010"d, "15Jan2010"d);
Num_weeks = Intck('Week', "01Jan2010"d, "15Jan2010"d);

Three_year = Intck('year3', "01Jan2010"d, "01Jan2013"d);
Num_years = Intck('year', "01Jan2010"d, "01Jan2013"d);
Proc Print;
run;

and you get  >>>>>>>>>>>>>>>>>>>>>> 



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.

No comments:

Post a Comment

Do provide us your feedback, it would help us serve your better.