SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3

INTCK Function

Returns the integer count of the number of interval boundaries between two dates, two times, or two datetime values

Category: Date and Time

Syntax

INTCK ( interval , from , to )

Arguments

interval

from

to

Details

The INTCK function counts the number of times the beginning of an interval is reached in moving from the from argument to the to argument. It does not count the number of complete intervals between those two values. For example, WEEK intervals are determined by the number of Sundays that occur between the from argument and the to argument, not by how many seven-day periods fall in between the from argument and the to argument.

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

Intervals that do not nest within years or days are aligned relative to the SAS date or datetime value 0. The arbitrary reference time of midnight on January 1, 1960, is used as the origin for non-shifted intervals, and shifted intervals are defined relative to that reference point.

For example, MONTH13 defines the intervals January 1, 1960, February 1, 1961, March 1, 1962, and so on, and the intervals December 1, 1958, November 1, 1957, and so on, before the base date January 1, 1960.

As another example, the interval specification WEEK6.13 defines six-week periods starting on second Fridays, and the convention of alignment relative to the period containing January 1, 1960, tells where to start counting to find out what dates correspond to the second Fridays of six-week intervals.

Table 4.3: Commonly Used Intervals with Optional Multiplier and Shift Indexes

Interval

Description

DAY3

Three-day intervals starting on Sunday

WEEK.7

Weekly with Saturday as the first day of the week

WEEK6.13

Six-week intervals starting on second Fridays

WEEK2

Biweekly intervals starting on first Sundays

WEEK1.1

Same as WEEK

WEEK.2

Weekly intervals starting on Mondays

WEEK6.3

Six-week intervals starting on first Tuesdays

WEEK6.11

Six-week intervals starting on second Wednesdays

WEEK4

Four-week intervals starting on first Sundays

WEEKDAY1W

Six-day week with Sunday as a weekend day

WEEKDAY35W

Five-day week with Tuesday and Thursday as weekend days (W indicates that day 3 and day 5 are weekend days)

WEEKDAY17W

Same as WEEKDAY

WEEKDAY67W

Five-day week with Friday and Saturday as weekend days

WEEKDAY3.2

Three-weekday intervals with Saturday and Sunday as weekend days (with the cycle three-weekday intervals aligned to Monday 4 Jan 1960)

TENDAY4.2

Four ten-day periods starting at the second TENDAY period

SEMIMONTH2.2

Intervals from the sixteenth of one month through the fifteenth of the next month

MONTH2.2

February-March, April-May, June-July, August-September, October-November, and December-January of the following year

MONTH2

January-February, March-April, May-June, July-August, September-October, November-December

QTR3.2

Three-month intervals starting on April 1, July 1, October 1, and January 1

SEMIYEAR.3

Six-month intervals, March-August and September-February

YEAR.10

Fiscal years starting in October

YEAR2.7

Biennial intervals starting in July of even years

YEAR2.19

Biennial intervals starting in July of odd years

YEAR4.11

Four-year intervals starting in November of leap years(frequency of U.S. presidential elections )

YEAR4.35

Four-year intervals starting in November of even years between leap years(frequency of U.S. midterm elections)

DTMONTH13

Thirteen-month intervals starting at midnight of January 1, 1960, such as November 1, 1957, December 1, 1958, January 1, 1960, February 1, 1961, and March 1, 1962

HOUR8.7

Eight- hour intervals starting at 6 AM, 2 PM, and 10 PM (might be used for work shifts)

Examples

SAS Statements

Results

qtr=intck('qtr','10jan95'd,'01jul95'd); put qtr;

2

year=intck('year','31dec94'd, '01jan95'd); put year;

1

year=intck('year','01jan94'd, '31dec94'd); put year;

semi=intck('semiyear','01jan95'd, '01jan98'd); put semi;

6

weekvar=intck('week2.2','01jan97'd, '31mar97'd); put weekvar;

6

wdvar=intck('weekday7w','01jan97'd, '01feb97'd); put wdvar;

26

y='year'; date1='1sep1991'd; date2='1sep2001'd; newyears=intck(y,date1,date2); put newyears;

10

y=trim('year '); date1='1sep1991'd + 300; date2='1sep2001'd - 300; newyears=intck(y,date1,date2); put newyears;

8

In the second example, INTCK returns a value of 1 even though only one day has elapsed. This is because the interval from December 31, 1994 to January 1, 1995 contains the starting point for the YEAR interval. In the third example, however, a value of 0 is returned even though 364 days have elapsed. This 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.

In the seventh example, the use of variables for the arguments is illustrated. The use of expressions for the arguments is illustrated in the last example.

See Also

Function:

Категории