Written and maintained by CASRAI Editorial Board
Published
On this page
The SAS INTCK function (also written “the INTCK function in SAS”) returns the number of interval boundaries of a given kind, such as month starts or year starts, that lie between two SAS date, time or datetime values. It does not count complete intervals by default: intck('month','31jan1991'd,'1feb1991'd) returns 1 even though only one day separates the dates, because the first of a month was crossed. Add the optional fourth argument 'continuous' when you need elapsed whole intervals instead.
What the SAS INTCK function is used for in research
Analysts reach for INTCK whenever a study dataset holds dates and the analysis needs a count of periods: months from enrolment to first visit, calendar quarters between two grant milestones, years since diagnosis, or the number of weekly reporting periods in a follow-up window. INTCK is a built-in function of the SAS language, and the FedSQL dialect has its own INTCK that returns a DOUBLE and accepts the same families of intervals.
The most common misreading is treating INTCK as a date subtraction. The SAS documentation describes the default behaviour as counting how many times the beginning of an interval is reached when moving from the first date to the second, not how many complete intervals fit between them. For cohort work this matters: a participant enrolled on 31 January and seen on 1 February is one “month” apart on the boundary count and zero full months apart on the elapsed count. The inverse operation, moving a date forward by a number of intervals, is done with INTNX; the CASRAI page on date formats in SAS covers how the resulting values are displayed.
Syntax
The documented form is INTCK(interval, start-date, end-date, 'method'). A custom-interval form also exists and requires the INTERVALDS system option to be set. Four rules from the function reference govern the arguments:
- interval is a character constant, variable or expression, in upper or lower case, and its type must match the start-date: date intervals for date values, datetime intervals (prefixed
DT, for exampleDTDAY) for datetime values, and time intervals for time values. - start-date and end-date are SAS date, time or datetime values. If the start is later than the end, the result is negative whenever the two values fall in different intervals.
- method is optional:
CONTINUOUS(abbreviatedCorCONT) orDISCRETE(DorDISC). The default is discrete. - Multipliers and shift indexes can be attached to the interval name, as in
YEAR2(every second year) orYEAR.3(years that start in March).
Date intervals in the FedSQL reference are DAY, WEEK, WEEKDAY, TENDAY, SEMIMONTH, MONTH, QTR, SEMIYEAR and YEAR; the datetime versions add the DT prefix, and time intervals are SECOND, MINUTE and HOUR.
How to install or access INTCK
There is nothing to install separately. INTCK ships as part of the SAS language, so it is available in any SAS session that can run a DATA step or PROC SQL, whether that is a desktop installation, a hosted environment or a SAS Viya session. Access therefore comes down to access to SAS itself. Two CASRAI pages cover the routes: SAS Academic for students and educators, and the SAS Viya platform guide for the cloud platform. The FedSQL version of INTCK is used when a query runs through the FedSQL language rather than the DATA step.
How to count intervals with INTCK step by step
- Check that both dates are real SAS date values. INTCK works on numeric SAS dates (or datetimes or times), not on display text. Date literals such as
'31jan1991'dare valid in a DATA step. For a column imported as text, convert it first; the coding in SAS guide shows the DATA step and PROC step structure around this. - Choose the interval and match its type. Use
'month','qtr','year'and similar for dates. If the variable is a datetime, use the DT form such as'dtmonth'. - Decide between boundaries and elapsed time. If you need to know how many calendar periods the interval touches (billing months, reporting quarters, calendar years of exposure), leave the method off, so the default discrete method applies. If you need anniversaries or full elapsed periods (months since a baseline visit), pass
'continuous'. - Write the call. A minimal program that prints the count to the log:
data _null_;
n_discrete = intck('month', '31jan1991'd, '1feb1991'd);
n_continuous = intck('month', '31jan1991'd, '1feb1991'd, 'continuous');
put n_discrete= n_continuous=;
run;
- Check the sign. Swapping start and end reverses the sign: the documentation gives
intck('month','31jan1991'd,'1feb1991'd)as 1 and the reversed order as -1.
Discrete and continuous answers can differ for the same pair of dates. The table below states the two rules side by side with the dates that make them diverge.
| Question | Discrete (default) | Continuous |
|---|---|---|
| What is counted | Times the beginning of the interval is reached between the two dates | Elapsed time measured from the start date |
| Month count, 31 Jan 1991 to 1 Feb 1991 | 1 (the first of February is crossed) | 0 (less than one month has elapsed) |
| Typical use named in the documentation | Calendar periods touched | Anniversaries and full elapsed periods |
| WEEK interval | Counts Sundays between the dates | Use this for true 7-day periods |
The documentation’s own continuous example is a wedding anniversary: from 14 February 2000 to 17 November 2010 the continuous year count is 10, and from 15 January to 15 February 2000 the continuous month count is 1. The data table at the end of this page lists these and the discrete examples from the reference, each with its result, so you can test a local SAS session against them.
INTCK with multipliers and shift indexes
The interval name can carry a number and a shift index that change where each period starts. The time series chapter of the SAS/ETS documentation gives these alignments, and INTCK counts the starts of the periods they define.
| Interval | What it means |
|---|---|
WEEK.1 |
Weeks that start on Sunday; INTCK counts Sundays |
WEEK.2 to WEEK.7 |
Weeks starting Monday (.2) through Saturday (.7) |
MONTH2 |
Two-month periods that start in odd-numbered months |
YEAR.3 |
Years that start in March |
HOUR8.7 |
Eight-hour periods running 06:00-14:00, 14:00-22:00 and 22:00-06:00 |
Custom intervals
Custom intervals, such as 4-4-5, 4-5-4 and 5-4-4 retail calendars, are defined in an interval data set and used through the custom-interval form of the function, with the INTERVALDS system option pointing at that data set. The documentation requires the intervals to be in ascending order with no gaps and no overlaps. This is rarely needed in research datasets but matters in fiscal-calendar reporting.
How to read the output
INTCK returns a number: a count of interval starts (discrete) or elapsed whole intervals (continuous), negative when the first date is later. Read the result against the rule that produced it:
- A result of 0 means no boundary was crossed (discrete) or no full interval elapsed (continuous). In the reference,
intck('month','1jan1991'd,'31jan1991'd)is 0 because both dates sit in the same month. - A result of 1 can be one day apart.
intck('year','31dec94'd,'01jan95'd)is 1, whileintck('year','01jan94'd,'31dec94'd)is 0 although it spans almost a full year. - A multiplier counts multiples.
intck('semiyear','01jan95'd,'01jan98'd)is 6, andintck('qtr','10jan95'd,'01jul95'd)is 2, because the starts of April and of July are reached. - The value is not an age. For an age in whole years, use the continuous method, which the documentation points to for anniversaries because it measures elapsed time from the start date; the discrete default counts January firsts and will overstate it for anyone whose birthday has not yet passed in the end year.
Troubleshooting INTCK
The result looks one too high
This is the discrete method working as documented: crossing a boundary counts, regardless of how many days passed. Add 'continuous' as the fourth argument if the analysis plan defines the quantity as completed months or years.
A date interval is used with datetime values, or the reverse
The documentation warns that using a date interval with a datetime value, or a datetime interval with a date, gives incorrect results without any error message in the log. If the answer is wildly large, check whether the variable holds seconds since 1 January 1960 (datetime) and switch to the DT interval, for example 'dtmonth'.
WEEK counts do not equal 7-day periods
With the discrete method, WEEK counts Sundays. For seven-day periods measured from the start date, the reference recommends the continuous method. For weeks that begin on another day, use a shift index such as 'week.2' for Monday starts.
A negative number appears
The start date is later than the end date. Reverse the arguments or take the absolute value if direction is irrelevant to the analysis.
The custom-interval form fails
That form depends on the INTERVALDS system option and an interval data set whose rows are ascending and free of gaps and overlaps, so check both before suspecting the function.
Free alternatives to INTCK
Other languages measure spans between dates, but none is a drop-in replacement for INTCK’s boundary counting. The table gives what each tool’s documentation says about the span it computes.
| Tool | Function | What its documentation describes |
|---|---|---|
| R, lubridate package | time_length() on an interval() |
Returns the exact length of an interval in the unit you choose, and for years and months takes into account that months and years do not have the same number of days. Its own example computes an exact age and an age at last anniversary with trunc(). |
| Python, dateutil package | relativedelta(dt1, dt2) |
Built from two dates, it represents an interval of time in relative components such as years, months and days. |
Of the two, lubridate’s time_length() is closest to the continuous method, because both measure elapsed time. For related R work see CASRAI’s lubridate guide and the comparison R vs. SAS for research analysis. To count calendar boundaries in R or Python you would write that logic yourself; neither documentation page describes a boundary-count function.
Sources
- SAS 9.3 Functions and CALL Routines Reference: INTCK Function, SAS Institute
- SAS 9.4 FedSQL Language Reference: INTCK Function, SAS Institute
- SAS/ETS User’s Guide, Date Intervals, Formats and Functions: INTCK, hosted by Simon Fraser University
- SAS/ETS User’s Guide, Date Intervals: multiples and shift indexes, hosted by Simon Fraser University
- lubridate reference: time_length(), tidyverse
- dateutil documentation: relativedelta, dateutil project
Data: INTCK results for documented date pairs, discrete and continuous methods
Worked INTCK results compiled from the SAS 9.3 Functions Reference, the SAS 9.4 FedSQL Language Reference and the SAS/ETS date-interval chapter, listing interval, start, end, method and the returned count so results can be reproduced in a SAS session.
| Example | Interval | Start date | End date | Method | Result (intervals) |
|---|---|---|---|---|---|
| Same month, discrete | MONTH | 01JAN1991 | 31JAN1991 | discrete | 0 |
| Month boundary across month end, discrete | MONTH | 31JAN1991 | 01FEB1991 | discrete | 1 |
| Reversed order, discrete | MONTH | 01FEB1991 | 31JAN1991 | discrete | -1 |
| Quarter, discrete | QTR | 10JAN1995 | 01JUL1995 | discrete | 2 |
| Year boundary one day apart, discrete | YEAR | 31DEC1994 | 01JAN1995 | discrete | 1 |
| Almost a full year, discrete | YEAR | 01JAN1994 | 31DEC1994 | discrete | 0 |
| Semiyear, discrete | SEMIYEAR | 01JAN1995 | 01JAN1998 | discrete | 6 |
| Anniversary years, continuous | YEAR | 14FEB2000 | 17NOV2010 | continuous | 10 |
| Elapsed month, continuous | MONTH | 15JAN2000 | 15FEB2000 | continuous | 1 |
Sources
- SAS 9.3 Functions Reference: INTCK (accessed 2026-11-17)
- SAS 9.4 FedSQL Language Reference: INTCK (accessed 2026-11-17)
- SAS/ETS date intervals: INTCK (accessed 2026-11-17)
Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.







