Returns the number of interval boundaries of a given kind that lie between two dates, times, or datetime values.

Category: | Date and Time |

specifies a character constant, a variable, or an expression that contains an interval name. Interval can appear in uppercase or lowercase. The possible values of interval are listed in Intervals Used with Date and Time Functions in SAS Language Reference: Concepts.

Multipliers and shift
indexes can be used with the basic interval names to construct more
complex interval specifications. The general form of an interval name
is as follows:

The three parts of the interval name are listed below:

specifies the name of the basic interval type. For example, YEAR specifies yearly intervals.

specifies an optional multiplier that sets the interval equal to a multiple of the period of the basic interval type. For example, the interval YEAR2 consists of two-year, or biennial, periods.

See | Incrementing Dates and Times by Using Multipliers and by Shifting Intervals for more information. |

specifies a user-defined interval that is defined by a SAS data set. Each observation contains two variables, begin and end.

Requirement | You must use the INTERVALDS system option if you use the custom-interval variable. |

See | Details for more information about custom intervals. |

specifies an optional shift index that shifts the interval to start at a specified subperiod starting point. For example, YEAR.3 specifies yearly periods shifted to start on the first of March of each calendar year and to end in February of the following year.

Restrictions | The shift index cannot be greater than the number of subperiods in the entire interval. For example, you could use YEAR2.24, but YEAR2.25 would be an error because there is no 25th month in a two-year interval. |

If the default shift period is the same as the interval type, then only multiperiod intervals can be shifted with the optional shift index. For example, MONTH type intervals shift by MONTH subperiods by default. Thus, monthly intervals cannot be shifted with the shift index. However, bimonthly intervals can be shifted with the shift index, because there are two MONTH intervals in each MONTH2 interval. For example, the interval name MONTH2.2 specifies bimonthly periods starting on the first day of even-numbered months. | |

See | Incrementing Dates and Times by Using Multipliers and by Shifting Intervals for more information. |

specifies a SAS expression that represents the starting SAS date, time, or datetime value.

specifies a SAS expression that represents the ending SAS date, time, or datetime value.

specifies that intervals are counted using either a discrete or a continuous method.

specifies that continuous time is measured. The interval is shifted based on the starting date.

The continuous method
is useful for calculating anniversaries. For example, you can calculate
the number of years married by executing the following program:

data b;

WeddingDay='14feb2000'd;

Today=today();

YearsMarried=INTCK('YEAR',WeddingDay,today(),'C');

format WeddingDay Today date9.;

run;

proc print data=b;

run;

For the CONTINUOUS
method, the distance in months between January 15, 2000, and February
15, 2000, is one month.

Alias | C or CONT |

specifies that discrete time is measured. The discrete method counts interval boundaries (for example, end of month).

The default discrete
method is useful to sort time series observations into bins for processing.
For example, daily data can be accumulated to monthly data for processing
as a monthly series.

For the DISCRETE method,
the distance in months between January 31, 2000, and February 1, 2000,
is one month.

Alias | D or DISC |

Default | DISCRETE |

All values within a
discrete time interval are interpreted as being equivalent. This means
that the dates of January 1, 2005 and January 15, 2005 are equivalent
when you specify a monthly interval. Both of these dates represent
the interval that begins on January 1, 2005 and ends on January 31,
2005. You can use the date for the beginning of the interval (January
1, 2005) or the date for the end of the interval (January 31, 2005)
to identify the interval. These dates represent all of the dates within
the monthly interval.

In the example

`intck('qtr','14JAN2005'd,'02SEP2005'd);`

,
the start-date ('14JAN2005'd)
is equivalent to the first quarter of 2005. The end-date ('02SEP2005'd)
is equivalent to the third quarter of 2005. The interval count, that
is, the number of times the beginning of an interval is reached in
moving from the start-date to
the end-date is 2.
The INTCK function using
the default discrete method counts the number of times the beginning
of an interval is reached in moving from the first date to the second.
It does not count the number of complete intervals between two dates:

Using the discrete method,
WEEK intervals are determined by the number of Sundays, the default
first day of the week, that occur between the start-date and
the end-date, and not by how
many seven-day periods fall between those dates. To count the number
of seven-day periods between start-date and end-date,
use the continuous method.

Both the multiple and
the shift-index arguments are
optional and default to 1. For example, YEAR, YEAR1, YEAR.1, and YEAR1.1
are all equivalent ways of specifying ordinary calendar years.

For more information
about working with date and time intervals, see Date and Time Intervals.

The intervals that you
need to use with SAS datetime values are SAS datetime intervals. Datetime
intervals are formed by adding the prefix "DT" to any date interval.
For example, MONTH is a SAS date interval, and DTMONTH is a SAS datetime
interval. Similarly, YEAR is a SAS date interval, and DTYEAR is a
SAS datetime interval.

To ensure correct results
with interval functions, use date intervals with date values and datetime
intervals with datetime values. SAS does not return an error message
if you use a date value with a datetime interval, but the results
are incorrect.

A custom time interval
is defined by a SAS data set. The data set must contain the begin variable;
it can also contain the end and season variables.
Each observation represents one interval with the begin variable
containing the start of the interval, and the end variable,
if present, containing the end of the interval. The intervals must
be listed in ascending order. There cannot be gaps between intervals,
and intervals cannot overlap.

The SAS system option
INTERVALDS= is used to define custom intervals and associate interval
data sets with new interval names. The following example shows how
to specify the INTERVALDS= system option:

options intervalds=(interval=libref.dataset-name);

For more information,
see Custom Time Intervals.

The retail industry
often accounts for its data by dividing the yearly calendar into four
13-week periods, based on one of the following formats: 4-4-5, 4-5-4,
or 5-4-4. The first, second, and third numbers specify the number
of weeks in the first, second, and third month of each period, respectively. For more information,
see Retail Calendar Intervals: ISO 8601 Compliant in SAS Language Reference: Concepts .

In the second example,
INTCK returns a value of 1 even though only one day has elapsed. This
result is returned because the interval from December 31, 1994, to
January 1, 1995, contains the starting point for the YEAR interval.
However, in the third example, a value of 0 is returned even though
364 days have elapsed. This result is because the period between January
1, 1994, and December 31, 1994, does not contain the starting point
for the interval.

In the fourth example,
SAS returns a value of 6 because January 1, 1995, through January
1, 1998, contains six semiyearly intervals. (Note that if the ending
date were December 31, 1997, SAS would count five intervals.) In the
fifth example, SAS returns a value of 6 because there are six two-week
intervals beginning on a first Monday during the period of January
1, 1997, through March 31, 1997. In the sixth example, SAS returns
the value 26. That indicates that beginning with January 1, 1997,
and counting only Saturdays as weekend days through February 1, 1997,
the period contains 26 weekdays.

data a; interval='month'; start='14FEB2000'd; end='13MAR2000'd; months_default=intck(interval, start, end); months_discrete=intck(interval, start, end,'d'); months_continuous=intck(interval, start, end,'c'); output; end='14MAR2000'd; months_default=intck(interval, start, end); months_discrete=intck(interval, start, end,'d'); months_continuous=intck(interval, start, end,'c'); output; start='31JAN2000'd; end='01FEB2000'd; months_default=intck(interval, start, end); months_discrete=intck(interval, start, end,'d'); months_continuous=intck(interval, start, end,'c'); output; format start end date.; run; proc print data=a; run;

Copyright © SAS Institute Inc. All rights reserved.