INTCK Function

Returns the number of interval boundaries of a given kind that lie between two SAS dates, times, or timestamp values encoded as DOUBLE.

Category: Date and Time
Returned data type: DOUBLE

Syntax

INTCK(start-date, end-date[, 'method'])

Arguments

interval[multiple][.shift-index]

specifies a basic or complex interval. Multipliers and shift indexes can be used with the basic interval names to construct more complex interval specifications. The three parts of the interval name are as follows:

interval

specifies a character constant, a variable, or an expression that contains an interval name such as WEEK, MONTH, or QTR.

Data type CHAR
Note The possible values of interval are listed in Intervals Used with Date and Time Functions in SAS Language Reference: Concepts.
Tip Interval can appear in uppercase or lowercase.
Example YEAR specifies year-based intervals.

multiple

specifies an optional multiplier that sets the interval equal to a multiple of the period of the basic interval type.

Data type INTEGER
See Incrementing Dates and Times By Using Multipliers and By Shifting Intervals in SAS Functions and CALL Routines: Reference for more information.
Example YEAR2 specifies a two-year, or biennial, interval type.

shift-index

specifies an optional shift index that shifts the interval to start at a specified subperiod starting point.

Restrictions The shift index cannot be greater than the number of subperiods in the whole 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, because MONTH type intervals shift by MONTH subperiods by default, 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.
Data type INTEGER
See Incrementing Dates and Times By Using Multipliers and By Shifting Intervals in SAS Functions and CALL Routines: Reference for more information.
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.

start-date

specifies an expression that represents the starting SAS date, time, or timestamp value.

Data type DOUBLE

end-date

specifies an expression that represents the ending SAS date, time, or timestamp value.

Data type DOUBLE

'method'

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

You must enclose method in quotation marks. Method can be one of these values:

CONTINUOUS

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

For example, the distance in months between January 15, 2013, and February 15, 2013, is one month.
Alias C or CONT

DISCRETE

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, 2013, and February 1, 2013, is one month.
Alias D or DISC
Default DISCRETE
Data type CHAR

Details

Calendar Interval Calculations

All values within a discrete time interval are interpreted as being equivalent. This means that the dates of January 1, 2013 and January 15, 2013 are equivalent when you specify a monthly interval. Both of these dates represent the interval that begins on January 1, 2013 and ends on January 31, 2013. You can use the date for the beginning of the interval (January 1, 2013) or the date for the end of the interval (January 31, 2013) to identify the interval. These dates represent all of the dates within the monthly interval.
In the following example, the start-date (Jan. 14, 2013) is equivalent to the first quarter of 2013.
select intck('qtr', date'2013-01-14', date'2013-09-02)';
The end-date (September 2, 2013) is equivalent to the third quarter of 2013. 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:
  • The following example returns 0, because the two dates are within the same month.
    select intck('month', date'2013-01-01', date'2013-01-31');
  • The following example returns 1, because the two dates lie in different months that are one month apart.
    select intck('month', date'2013-01-31', date'2013-02-01');
  • The following example returns –1 because the first date is in a later discrete interval than the second date. (INTCK returns a negative value whenever the first date is later than the second date and the two dates are not in the same discrete interval.)
    select intck('month', date'2013-02-01', date'2013-01-31');
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 in SAS Functions and CALL Routines: Reference.

Intervals by Category

Intervals Used with Date and Time Functions
Category
Interval
Definition
Default Starting Point
Shift Period
Example
Description
Date
DAY
Daily intervals
Each day
Days
DAY3
Three-day intervals starting on Sunday
WEEK
Weekly intervals of seven days
Each Sunday
Days (1=Sunday … 7=Saturday)
WEEK.7
Weekly with Saturday as the first day of the week
WEEKDAY
<daysW>
Daily intervals with Friday-Saturday-Sunday
Each day
Days
WEEKDAY1W
Six-day week with Sunday as a weekend day
counted as the same day (five-day work week with a Saturday-Sunday weekend). days identifies the weekend days by number (1=Sunday ... 7=Saturday). By default, days=17.
WEEKDAY35W
Five-day week with Tuesday and Thursday as weekend days (W indicates that day 3 and day 5 are weekend days)
TENDAY
Ten-day intervals (a U.S. automobile industry convention)
First, 11th, and 21st of each month
Ten-day periods
TENDAY4.2
Four ten-day periods starting at the second TENDAY period
SEMIMONTH
Half-month intervals
First and 16th of each month
Semi-monthly periods
SEMIMONTH2.2
Intervals from the 16th of one month through the 15th of the next month
MONTH
Monthly intervals
First of each month
Months
MONTH2.2
February-March, April-May, June-July, August-September, October-November, and December-January of the following year
QTR
Quarterly (three-month) intervals
January 1
Months
QTR3.2
Three-month intervals starting on April 1, July 1, October 1, and January 1
April 1
July 1
October 1
SEMIYEAR
Semiannual (six-month) intervals
January 1
Months
SEMIYEAR.3
Six-month intervals, March-August, and September-February
July 1
YEAR
Yearly intervals
January 1
Months
Datetime
Add DT to any of the date intervals
Interval that corresponds to the associated date interval
Midnight of January 1, 1960
DTMONTH
DTWEEKDAY
Time
SECOND
Second intervals
Start of the day (midnight)
Seconds
MINUTE
Minute intervals
Start of the day (midnight)
Minutes
HOUR
Hourly intervals
Start of the day (midnight)
Hours

Retail Calendar 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.

Example

The following statements illustrate the INTCK function:
Statements
Results
select intck('qtr', date'2013-01-10', 
date'2013-07-01');
2
select intck('year', date'2012-12-31', 
date'2013-01-01');
1
select intck('year', date'2013-01-01', 
date'2013-12-31');
0
select intck('semiyear', date'2010-01-01', 
date'2013-01-01');
6
select intck('week2.2', date'2013-01-07', 
date'2013-04-01');
6
select intck('weekday7w', date'2013-01-01', 
date'2013-02-01');
27
select intck('year', date'2003-09-01', 
date'2013-09-01');
10
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, 2012, to January 1, 2013, 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, 2013, and December 31, 2013, does not contain the starting point for the interval.
In the fourth example, SAS returns a value of 6 because January 1, 2010, through January 1, 2013, contains six semiyearly intervals. (Note that if the ending date were December 31, 2012, 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 7, 2013, through April 1, 2013. In the sixth example, SAS returns the value 27. That indicates that beginning with January 1, 2013, and counting only Saturdays as weekend days through February 1, 2013, the period contains 27 weekdays. The last example specifies the number of years that have elapsed between the specified dates (10).

See Also

Other References:
Functions:
Last updated: February 23, 2017