intck1

How to Use INTCK Function in SAS (With Examples)

The INTCK function in SAS is an essential tool for sophisticated chronological analysis, used specifically to calculate the number of specified intervals that occur between two given date values or datetime values. This powerful function allows data analysts and programmers to perform detailed, precise calculations for various time periods, moving beyond simple subtraction of dates. It is indispensable when the goal is to define specific time boundaries, such as calculating the exact number of months, quarters, or years elapsed between two milestones. The function establishes a defined time interval—such as a month boundary or a year boundary—and then counts how many of those boundaries are crossed between the starting point and the ending point. Understanding its core required arguments—start-time, end-time, and interval—along with the optional method parameter, is key to mastering time-based computations in the SAS environment. This comprehensive guide provides practical examples demonstrating how to leverage INTCK effectively.


The INTCK function in SAS is the standard and most reliable way to calculate the precise chronological difference between two date or datetime fields, determining how many full or partial intervals fit between them.

Understanding the Core Purpose of the INTCK Function

The INTCK function is fundamental for any time-based analysis performed in SAS, as it provides a method for counting logical time units rather than relying solely on raw day counts. This distinction is vital when dealing with calendar-sensitive periods. When a financial analyst needs to know the number of fiscal quarters between two dates, or an HR professional needs to count the number of full years of service for an employee, INTCK correctly interprets calendar rules (like month lengths or leap years) to provide an accurate count of interval boundaries crossed.

Its application spans numerous fields, including finance (calculating interest periods), human resources (determining employee tenure in full years or months), and research (analyzing time series data). The ability to specify the exact unit of measurement—whether it is a day, week, month, or quarter—gives the user unparalleled flexibility in time-based data manipulation. Furthermore, the function supports advanced interval types, allowing calculations based on fiscal periods, specialized shifts, or custom calendars. Mastering INTCK is fundamental for anyone performing deep dive data analysis using SAS programming.

It is important to understand that the function does not measure the duration of time; rather, it measures the number of interval markers that fall between the two endpoints. For example, if we measure the difference in ‘MONTHS’ between December 15th and January 15th, the result is 1, because the January 1st month boundary was crossed. If the same dates are used to calculate the difference in ‘YEARS’, the result is 0, because no year boundary was crossed.

Detailed Syntax and Argument Breakdown

The INTCK function employs a straightforward yet powerful syntax structure. While the core function requires three arguments, it often utilizes a fourth, optional argument to handle specific counting methodologies. Understanding each parameter is critical to ensuring accurate output based on the desired interval calculation. The syntax utilizes character strings for both the interval and the optional method, while the date arguments must be valid SAS numeric date, datetime, or time values.

The basic syntax structure is as follows:

INTCK(interval, start date, end date, method)

The arguments break down into the following components:

  • interval: This is a required character string that specifies the unit of time used for the calculation. Common values include ‘DAY’, ‘WEEK’, ‘MONTH’, ‘QTR’ (Quarter), and ‘YEAR’. SAS also supports more granular intervals like ‘HOUR’, ‘MINUTE’, and ‘SECOND’, as well as specialized intervals like ‘WEEKDAY’ or ‘DTCWEEK’.
  • start date: This is a required numeric value representing the beginning point of the period. This value must be a SAS date value, datetime value, or time value, depending on the interval specified.
  • end date: This is a required numeric value representing the ending point of the period. Like the start date, this must be a valid SAS date, datetime, or time value compatible with the interval type.
  • method: This is an optional character argument, usually specified as ‘D’ for discrete or ‘C’ for continuous (complete). This parameter controls how the interval boundaries are counted, which is especially important for ambiguous intervals like months or years. If omitted, SAS defaults to the standard method, which typically aligns with the discrete counting rule.

It is important to remember that the INTCK function calculates the number of times an interval boundary is crossed between the start date and the end date. If the end date occurs before the start date, the resulting count will be a negative number, reflecting the backward calculation in time, which can be useful for calculating years until a future target date.

Exploring Common Interval Specifications

The flexibility of the INTCK function stems largely from the variety of interval strings it accepts. Choosing the correct interval is paramount to achieving the desired statistical measurement. While ‘DAY’ simply counts the number of days (which could also be achieved via date subtraction), intervals like ‘MONTH’ or ‘QTR’ introduce complex calendar rules that simple arithmetic cannot manage reliably. For example, the ‘WEEK’ interval counts the number of Sunday boundaries crossed, assuming the SAS default week definition.

For instance, when using the ‘MONTH’ interval, the function counts the number of first-of-the-month boundaries crossed. If a period runs from January 30th to February 1st, only one month boundary (the boundary between January and February) is crossed, resulting in a count of 1. The interval string is always enclosed in quotation marks, such as ‘MONTHS’ or ‘YEARS’. Utilizing plural forms, like ‘MONTHS’ instead of ‘MONTH’, is generally preferred for clarity, although both are often accepted by the function.

Specialized intervals also exist to accommodate non-standard reporting cycles. For example, ‘SEMIYEAR’ calculates half-year periods, useful for semi-annual financial reporting. Additionally, SAS allows for the customization of starting points for certain intervals using suffixes. For example, ‘MONTH2’ calculates intervals starting on the second day of the month, and ‘QTR3’ defines quarters starting in March, June, September, and December. This advanced feature enables analysts to align calculations precisely with organizational or regulatory reporting cycles that do not adhere to the standard calendar year.

Setting Up the Demonstration Dataset in SAS

To fully illustrate the practical application of the INTCK function, we will establish a sample dataset containing various date pairs. This dataset, named original_data, includes two variables: start_date and end_date. It is crucial to use the appropriate date format in SAS, as date variables are stored internally as the number of days since January 1, 1960. We use the DATE9. format to display these numeric values clearly as DDMMMYYYY, making the input and output easily readable.

The following data step creates five records, each representing a unique time span, allowing us to observe how INTCK handles differences ranging from a few days to several years. The DATALINES statement provides the raw input data, which SAS interprets using the specified date informat (DATE9.). This setup ensures that we are working with correct SAS date values before applying the INTCK function.

/*create dataset*/
data original_data;
    format start_date end_date date9.;
    input start_date :date9. end_date :date9.;
    datalines;
01JAN2022 09JAN2022
01FEB2022 22FEB2022 
14MAR2022 04APR2022
01MAY2022 14AUG2023
06AUG2022 10NOV2024
;
run;

/*view dataset*/
proc print data=original_data;

Calculating Intervals Using the Default (Discrete) Method

The first application of the INTCK function will utilize the default behavior, which is the discrete method. When the optional method argument is omitted, SAS automatically implements the counting mechanism that respects the interval boundaries. In this approach, INTCK counts every instance where the boundary of the specified interval is crossed between the start date and the end date, inclusive of partial intervals. This method is often preferred when analyzing the span of time during which an activity took place, even if the activity did not cover a full unit of the interval.

We will create five new variables (days_diff, weeks_diff, months_diff, qtr_diff, and years_diff) to showcase the calculation for the five most common intervals. Observe how the results for weeks, months, and quarters are calculated based on boundary crossings rather than simple proportional time division. For example, the difference in months between 01FEB2022 and 22FEB2022 is 0, because no month boundary (the start of a new month) was crossed. However, the difference between 14MAR2022 and 04APR2022 is 1, as the April 1st boundary was crossed.

/*create new dataset*/
data new_data;
    set original_data;
    days_diff = intck('day', start_date, end_date);
    weeks_diff = intck('weeks', start_date, end_date);
    months_diff = intck('months', start_date, end_date);
    qtr_diff = intck('qtr', start_date, end_date);
    years_diff = intck('years', start_date, end_date);
run;

/*view new dataset*/
proc print data=new_data;

 

INTCK function in SAS

Upon reviewing the output table, the five derived variables successfully display the difference between the start_date and end_date according to the specified interval. For longer time spans, such as the last observation (Aug 6, 2022 to Nov 10, 2024), we see that the difference is 827 days, 117 weeks, 27 months, 9 quarters, and 2 years. Note that the ‘MONTHS’ calculation yields 27 because 27 month boundaries were crossed between the two dates. The discrete method tends to maximize the count by including the endpoints implicitly, counting any interval that is touched by the time span.

The Critical Role of the ‘Method’ Argument: Discrete vs. Continuous

While the default (discrete) method provides a count based on interval boundary crossings, many analytical requirements necessitate counting only the number of complete, non-overlapping intervals that fit entirely within the start and end dates. This is where the optional fourth argument, method, becomes essential. The two primary methods are Discrete (‘D’) and Continuous (‘C’).

The Discrete method, used by default when the argument is omitted or specified as ‘D’, counts the number of interval starting points that fall between the start and end dates. This method is often suitable for determining how many distinct periods (e.g., calendar months) are encompassed by a date range, regardless of whether the start date falls exactly on the beginning of that period.

Conversely, the Continuous method, specified by using the argument ‘C’, calculates the number of complete, whole intervals. It determines how many full units of the specified interval can be placed sequentially between the start and end points without overlapping the end date. This is often more intuitive for calculating tenure, age, or full calendar cycles. Using the example of calculating ‘WEEKS’ between January 1st and January 9th: the discrete count is 2 (two week boundaries crossed), but the continuous count must be 1, because only one full 7-day period has elapsed.

Implementing the Continuous Method for Complete Intervals

To demonstrate the impact of using the ‘C’ (Continuous) method, we will rerun the previous calculations, explicitly adding 'C' as the fourth argument in the INTCK function call. This modification forces the function to only count the number of complete intervals, providing a significantly different perspective on the time spans, particularly for intervals shorter than the total duration. Using the continuous method is crucial for ensuring that calculations such as employee seniority or eligibility for annual review are based only on fully completed time units.

The continuous counting method is particularly relevant when tracking accumulated full periods. For example, calculating the number of full years an employee has worked (for benefits eligibility) or the number of complete quarterly reports due within a project timeframe relies heavily on this approach. The code below is identical to the previous example, with the critical addition of ,'C' to all INTCK calls.

/*create new dataset using Continuous method ('C')*/
data new_data_continuous;
    set original_data;
    days_diff = intck('day', start_date, end_date, 'c');
    weeks_diff = intck('weeks', start_date, end_date, 'c');
    months_diff = intck('months', start_date, end_date, 'c');
    qtr_diff = intck('qtr', start_date, end_date, 'c');
    years_diff = intck('years', start_date, end_date, 'c');
run;

/*view new dataset*/
proc print data=new_data_continuous;

Interpreting Results with the Continuous Method

The results generated using the continuous method reveal significant differences, particularly for shorter time frames, compared to the discrete method shown earlier. It is essential to carefully analyze these discrepancies to understand the precise meaning of the calculated interval counts. The continuous method is generally more restrictive, yielding a count that reflects only completed cycles, ensuring rigor in time-based measurements.

Consider the first observation again: January 1st, 2022 to January 9th, 2022. The total time span is 8 days. In the previous discrete table, the weeks_diff was 2. However, in this continuous table, the weeks_diff is 1. This is because only one whole week (7 days) fits completely between January 1st and January 9th. The continuous method enforces the requirement that the full length of the interval must be accommodated within the time span before it is counted.

This distinction is crucial when dealing with monthly or yearly data. For the third observation (March 14, 2022, to April 4, 2022), the discrete method returned 1 month (as the April 1st boundary was crossed). The continuous method, however, returns 0 months, because a full month (which would span from March 14 to April 14) did not elapse within the defined period. Understanding whether you need boundary crossings (discrete) or fully completed intervals (continuous) dictates which method argument you must utilize in the INTCK function.

Advanced Considerations and Related Functions

While INTCK is excellent for counting intervals, SAS offers related functions that complement its functionality, allowing for a comprehensive approach to date manipulation. One important complementary function is INTNX (Interval Next), which advances a date by a specified number of intervals. For example, INTNX(‘MONTH’, ’01JAN2022’d, 3) would return April 1, 2022. Using INTCK and INTNX together allows for precise time series creation and manipulation, facilitating the generation of accurate forecast dates or reporting cycles.

Another crucial element in advanced SAS time calculations is ensuring that the start and end arguments are correctly formatted SAS numeric date values. If datetime values are used (which include time components), the corresponding interval must be specified at the datetime level (e.g., ‘DTMONTH’, ‘DTHOUR’), otherwise, the results may be inaccurate due to truncation or improper boundary alignment. For example, if you use ‘MONTH’ with datetime values, SAS truncates the datetime to the date part, potentially losing precision. Conversely, if you use ‘DTHOUR’ with simple date values, SAS assigns a default time (midnight), which could also skew results if time granularity is critical. By combining the power of INTCK, INTNX, and careful attention to date formats, SAS users can efficiently manage and analyze complex chronological datasets.

Cite this article

stats writer (2025). How to Use INTCK Function in SAS (With Examples). PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-to-use-intck-function-in-sas-with-examples/

stats writer. "How to Use INTCK Function in SAS (With Examples)." PSYCHOLOGICAL SCALES, 19 Nov. 2025, https://scales.arabpsychology.com/stats/how-to-use-intck-function-in-sas-with-examples/.

stats writer. "How to Use INTCK Function in SAS (With Examples)." PSYCHOLOGICAL SCALES, 2025. https://scales.arabpsychology.com/stats/how-to-use-intck-function-in-sas-with-examples/.

stats writer (2025) 'How to Use INTCK Function in SAS (With Examples)', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-to-use-intck-function-in-sas-with-examples/.

[1] stats writer, "How to Use INTCK Function in SAS (With Examples)," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, November, 2025.

stats writer. How to Use INTCK Function in SAS (With Examples). PSYCHOLOGICAL SCALES. 2025;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top