Skip to main content
v2026.11,986 entries · CC-BY 4.0

SAS INTCK Function: Syntax, Discrete vs Continuous and Examples

SAS INTCK counts interval boundaries between two dates. See syntax, discrete vs continuous methods, worked results and fixes for common errors.

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 example DTDAY) 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 (abbreviated C or CONT) or DISCRETE (D or DISC). The default is discrete.
  • Multipliers and shift indexes can be attached to the interval name, as in YEAR2 (every second year) or YEAR.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

  1. 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'd are 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.
  2. 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'.
  3. 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'.
  4. 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;
  1. 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, while intck('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, and intck('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

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.

INTCK results for documented date pairs, discrete and continuous methods
ExampleIntervalStart dateEnd dateMethodResult (intervals)
Same month, discreteMONTH01JAN199131JAN1991discrete0
Month boundary across month end, discreteMONTH31JAN199101FEB1991discrete1
Reversed order, discreteMONTH01FEB199131JAN1991discrete-1
Quarter, discreteQTR10JAN199501JUL1995discrete2
Year boundary one day apart, discreteYEAR31DEC199401JAN1995discrete1
Almost a full year, discreteYEAR01JAN199431DEC1994discrete0
Semiyear, discreteSEMIYEAR01JAN199501JAN1998discrete6
Anniversary years, continuousYEAR14FEB200017NOV2010continuous10
Elapsed month, continuousMONTH15JAN200015FEB2000continuous1

Sources

Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about SAS INTCK Function: Syntax, Discrete vs Continuous and Examples

2 free questions a day, no account.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →