INTCK Function in SAS (Explained With Examples)

The INTCK function in SAS returns the number of interval boundaries that lie between two SAS dates, times, or timestamp values. It’s a super powerful function in SAS which is being used in many various ways.

I have seen it being used extensively in the where clause where you filter out the data by calculating desired date, time, or timestamp values. The function returns the number of time intervals that occur between two dates or times, such as the number of months, days, or hours.

Basic Syntax:

				INTCK(interval , start-date-time, end-date-time, <'method'>)
			
  • interval: – It’s a time interval like year, month, week, day, hour, minute, second, etc. Specify that interval in single quotes.
  • start-date-time: – It’s a start date or time to calculate the number of periods.
  • end-date-time: – It’s an end date or time to calculate the number of periods.
  • method: – It’s an optional parameter. You can define a method to calculate differences.

The default is “DISCRETE” method but you can specify if you want to use the “CONTINUOUS” method.

The INTCK Function in SAS (real-life scenarios)

The INTCK function can be used in multiple scenarios but here are those are on top of my mind where it can be used extensively:

1. Calculate Age: When you have a ‘birthday’ date in the input data set, it is very easy to calculate age for each row by setting the baseline. To calculate current age, the baseline would be today’s date.’

The INTCK function can be used to calculate age by counting days between birth date and current date. Check out this example.

2. Loan Calculations: When calculating the interest on a loan, you may need to calculate the number of days between two payment dates to calculate the interest amount. 

The INTCK function can be used to calculate the number of days between the payment dates, which can be used to determine the interest amount.

3. Manufacturing Industry: In manufacturing, it is often necessary to calculate the time between two events, such as the time between two machine breakdowns or the time between two production runs. 

The INTCK function can be used to calculate the time intervals, which can be used to identify opportunities for process improvement and cost savings.

4. Travel Period: When calculating travel time or days between two journeys, you can use start and end date and time between the journey. The INTCK function can be used to calculate travel time, layover time, travel days, etc. 

5. Human Resources: In the HR system there are lots of formulas you need to apply when working in HR data. 

The INTCK function can be used to calculate the number of hours worked by employees, no of working days, tenure of an employee with the company, no of quarterly payments paid, and so on.

6. Medical Research: In medical research, it is often necessary to calculate the duration of treatment and follow-up periods for clinical trials. 

The INTCK function can be used to determine the number of days between the start and end dates of a trial, which can be used to analyse the effectiveness of the treatment.

The INTCK Function Examples

This is the simplest example where I’m calculating years between the two dates, date1= 01JAN2023, date2=01JAN2025, and store it in a new variable “no_of_years”.

				data intck_demo;
	format date1 date2 date9.;
	date1='01JAN2025'd;
	date2='01JAN2030'd;
	no_of_years=intck ('year', date1, date2);

proc print data=intck_demo;
run;

			
intck function in SAS 1

The SAS INTCK Examples with DATE

Here is the combined example where you can see most common “intervals” are covered which are being used in the INTCK function with SAS date.

The following table will help you understand different Intervals in the INTCK function.

CategoryIntervalDefinition
DATEYEARDaily intervals
 SEMIYEARSemiannual (six-month) intervals
 QUARTERQuarterly (three-month) intervals
 MONTHMonthly intervals
 SEMIMONTHHalf-month intervals
 WEEKWeekly intervals of seven days. Default it counts Sunday as the first day of the week.
 DAYDaily intervals

Example:

				data intck_demo;
	format date1 date2 date9.;
	date1='01JAN2025'd;
	date2='01JAN2030'd;
	no_of_years=intck ('YEAR', date1, date2);
	no_of_semiyears=intck ('SEMIYEAR', date1, date2);
	no_of_quarters=intck ('QUARTER', date1, date2);
	no_of_months=intck ('MONTH', date1, date2);
	no_of_semimonths=intck ('SEMIMONTH', date1, date2);
	no_of_weeks=intck ('WEEK', date1, date2);
	no_of_days=intck ('DAY', date1, date2);

proc print data=intck_demo;
run;

			
intck function in SAS 2 example

WEEKDAY<daysW> in INTCK Function:

As per your requirement you can set the weekdays and weekends by specifying correct WEEKDAY<daysW> intervals. Here is the table how SAS treats week days:

Sunday1
Monday2
Tuesday3
Wednesday4
Thursday5
Friday6
Saturday7

INTCK WEEKDAY Examples:

  • WEEKDAY1W: Six-day week with Sunday as a weekend day
  • WEEKDAY2W: Six-day week with Monday as a weekend day
  • WEEKDAY17W: Five-day week with Sunday and Saturday are weekend days
  • WEEKDAY56W: Five-day week with Thursday and Friday are weekend days
  • WEEKDAY: Five-day week with Sunday and Saturday are weekend days. The WEEKDAY and WEEKDAY17W are the same interval.
				data intck_weekdays_demo;
	format date1 date2 date9.;
	date1='01MAR2025'd;
	date2='01JUN2025'd;
	weekdays=intck ('WEEKDAY', date1, date2);
	weekdays_1w=intck ('WEEKDAY1W', date1, date2);
	weekdays_2w=intck ('WEEKDAY2W', date1, date2);
	weekdays_17w=intck ('WEEKDAY17W', date1, date2);
	weekdays_56w=intck ('WEEKDAY56W', date1, date2);

proc print data=intck_weekdays_demo;
run;
			
intck function in SAS 3 example

The SAS INTCK Examples with DATE and TIME

When dealing with datetime you can’t use intervals mentioned above. There are different intervals available for datetime such as hour, minute, second, dtday, dtweekday, etc.

Category

Interval

Definition

DATETIME

DTDAY

Daily intervals

 

DTWEEKDAY

Weekday intervals

TIME

HOUR

Intervals in hours

 

MINUTE

Intervals in minutes

 

SECOND

Intervals in seconds

 

Calculate days and weekdays between two datetime values:

				data intck_demo;
	format datetime1 datetime2 datetime25.;
	datetime1='01MAR2025:05:00:00'dt;
	datetime2='01JUN2025:05:00:00'dt;
	days=intck ('DTDAY', datetime1, datetime2);
	weekdays=intck ('DTWEEKDAY', datetime1, datetime2);

proc print data=intck_demo;
run;
			
intck function in SAS 4 example

Calculate difference between two datetime values:

Here is one more example where you want to calculate hours, minutes, seconds, between two datetime values, you can use the INTCK function in SAS with ‘hour’, ‘minute’, and ‘second’ intervals.

				data intck_demo;
	format datetime1 datetime2 datetime25.;
	datetime1='01MAR2025:04:50:00'dt;
	datetime2='01MAR2025:11:55:00'dt;
	hours=intck('hour', datetime1, datetime2);
	minutes=intck('minute', datetime1, datetime2);
	seconds=intck('second', datetime1, datetime2);

proc print data=intck_demo;
run;
			
intck function in SAS 5 example

Calculate difference between two time values:

Here is another example where you want to calculate hours, minutes, seconds, between two time values, you can use the INTCK function in SAS with ‘hour’, ‘minute’, and ‘second’ intervals.

				data intck_demo;
	format time1 time2 time8.;
	time1='04:50:00't;
	time2='11:55:00't;
	hours=intck('hour', time1, time2);
	minutes=intck('minute', time1, time2);
	seconds=intck('second', time1, time2);

proc print data=intck_demo;
run;

			
intck function in SAS (difference in Time values)

INTCK Function: DISCRETE and CONTINUOUS method in SAS

When you use the INTCK function it is by default considered as a DISCRETE method unless and until you specify it as a CONTINUOUS method.

Syntax of INTCK function:

				INTCK(interval , start-date-time, end-date-time, <'method'>)
			

method: – It’s an optional parameter. You can define a method to calculate differences. The default is “DISCRETE” but you can specify if you want to use the “CONTINUOUS” method.

Example of DISCRETE INTCK Function:

				data descrete_intck;
	month1=intck('month', '01MAR2025'd, '31MAR2025'd);
	month2=intck('month', '25MAR2025'd, '05APR2025'd);
	month3=intck('month', '25MAR2025'd, '25APR2025'd);

proc print data=descrete_intck;
run;
			
intck function in SAS descrete method

Did you notice anything wrong with the month2 variable in the above example? 

It is calculated from date1= 25MAR2025 and date2=05APR2025. The difference between these two dates is 10 days but just because the month has changed from March to April, the INTCK function (with discrete method) considers the difference between them to be 1 month. 

But this is quite not true. You can fix this by using the CONTINUOUS method in INTCK. 

Example of Continuous INTCK Function:

				data continuous_intck;
	month1=intck('month', '01MAR2025'd, '31MAR2025'd, 'C');
	month2=intck('month', '25MAR2025'd, '05APR2025'd, 'C');
	month3=intck('month', '25MAR2025'd, '25APR2025'd, 'C');

proc print data=continuous_intck;
run;
			
intck function in SAS continuous method

FAQ

What is INTCK function in SAS?

The INTCK function in SAS returns the number of interval boundaries that lie between two SAS dates, times, or timestamp values.

How to calculate difference between two date and time?

To calculate difference in days, months, or years, you can use INTCK function in SAS. It has wide range of intervals to specify and calculate intended differences between the dates or time.