INTCK Function


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

  • 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 the 'Intervals Used with Date and Time Functions' table in SAS Language Reference: Concepts .

  • Requirement: The type of interval (date, datetime, or time) must match the type of value in from .

    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 :

  • interval<n.s>

    • The three parts of the interval name are

    • interval

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

    • n

      • 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: 'Details' on page 600 for more information.

    • s

      • 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.

      • Restriction: 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 twenty-fifth month in a two-year interval.

      • Restriction: 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. The interval name MONTH2.2, for example, specifies bimonthly periods starting on the first day of even-numbered months.

      • See: 'Details' on page 600 for more information.

from

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

to

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

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:

  • 'INTNX Function' on page 602




SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 704

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net