sas date function INTCK ( )

This has been demonstrated below;

SAS INTCK( ) Function

SYNTAX: INTCK (interval<multiples><shift>, start_date, end_date);

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

This argument also comes with optional argument modifiers called multiples and shifts

Multiples – a single interval can be treated in its multiples form like for a month interval a 3 month period can also be tracked as MONTH3. ‘MONTH2’ interval will calculate how many 2 months periods have passed between two days.

This has been demonstrated with the example below.

Shift – It’s an adjustment to shift the interval start date/time. For example if we want to know how many ‘YEAR’s passed between 1st FEB 2008 and 1st JAN 2010; if you used plain interval ‘YEAR’; INTCK ( ) will return 2 as it considers calendar year. However if someone wants to be more specific and wants to know how many actual years passed between 2 dates then one can use ‘YEAR.2’ and then INTCK will return 1.

This has been demonstrated with the example below.

  • start-date – it is start date between two dates of our interest.

  • end-date – it is other date or end date between two dates of our interest.

It is not mandatory to use smaller date as start-date and larger date as end-date. You can use it in reverse manner as well; however when end-date is smaller than start-date the result will be negative number.

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

INTCK() is basically used to get the number of time intervals between two dates. Time intervals can be specified in ‘MONTH’, ‘WEEK’, ‘QTR’, ‘YEAR’ etc.

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; lets take an example of ‘YEAR’ interval, for any two dates within the same calendar year will return 0; but 31st DEC 2010 and its next day 1st JAN 2011 will return 1, moreover 1JAN 2010 and 31st DEC 2011 will also return 1.

Example: Counting number of working days between 2 dates using SAS INTCK( ) Function

SAS Code:

proc print data = temp;

run;

PROC PRINT OUTPUT :

data temp;

date1 = "21MAR2010"d;

date2 = "31MAY2010"d;

no_of_working_days = intck ('WEEKDAY', date1, date2);

format date1 date2 date9.;

run;

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

Example: Finding no of trimesters between two dates using SAS INTCK( ) Function

SAS Code:

data t;

date1 = "21MAR2010"d;

date2 = "31MAY2012"d;

no_of_trimesters = intck ('MONTH3', date1, date2);

format date1 date2 date9.;

run;

proc print data = temp;

run;

PROC PRINT OUTPUT :

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

If we see the code more closely;

The ‘interval’ used in the INTCK function above is ‘MONTH3’ which specifies that interval should be calculated as 3 multiplied to a month i.e. interval is of 3 months.

Example: Finding exact age in years using SAS INTCK( ) Function

SAS Code:

proc print data = temp;

run;

PROC PRINT OUTPUT :

data t;

dob = "21MAR1969"d;

curr_date = "01JAN2010"d;

age_in_yrs = intck ('YEAR', dob, curr_date);

exact_age_in_yrs = intck ('YEAR.3', dob, curr_date);

format dob curr_date date9.;

run;

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

If we see the code more closely;

In the 3rd statement while calculating age_in_yrs the interval used is ‘YEAR’ and that in case of 4th statement for calculating exact_age_in_yrs is ‘YEAR.3’

‘YEAR.3’ specifies the shift of starting date for calculation; as date of birth is in MARCH the year will get completed in MARCH only and not in JAN.

One can clearly find the difference between two calculations. As age_in_yrs gives 41 where exact_age_in_yrs is showing 40.