Chapter Contents |
Previous |
Next |
Definitions |
Syntax |
name<multiple><.starting-point> |
The terms in an interval have the following definitions:
Intervals By Category |
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 | Each Sunday | Days (1=Sunday ... 7=Saturday | WEEK.7 | Weekly with Saturday as the first day of the week | |
WEEKDAY <daysW> |
Daily intervals with weekend days treated as part of the preceding weekday. Days identifies the weekend days by number (1=Sunday ... 7=Saturday). By default, days=17. | Each day | Days | WEEKDAY1W WEEKDAY35W |
Six-day week with Sunday as a weekend day 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, eleventh, and twenty-first of each month | TENDAY periods | TENDAY4.2 | Four ten-day periods starting at the second TENDAY period | |
SEMIMONTH | Half-month intervals | First and sixteenth of each month | SEMIMONTH periods | SEMIMONTH2.2 | Intervals from the sixteenth of one month through the fifteenth 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 April 1 July 1 October 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 date interval | DTMONTH | |||
DTWEEKDAY | ||||||
Time | SECOND | Second intervals | Each second | Seconds | ||
MINUTE | Minute intervals | Each minute | Minutes | |||
HOUR | Hourly intervals | Each hour | Hours |
Example 3: Calculating a Duration |
This program reads the project start and end dates and calculates the duration between them.
data projects; options nodate pageno=1 linesize=80 pagesize=60; input Projid startdate date9. enddate date9.; Duration=enddate-startdate; datalines; 398 17oct1997 02nov1997 942 22jan1998 10mar1998 167 15dec1999 15feb2000 250 04jan2001 11jan2001 ; proc print data=projects; format startdate enddate date9.; title 'Days Between Project Start and Project End'; run;
Output from the PRINT Procedure
Days Between Project Start and Project End run 8 Obs Projid Startdate Enddate Duration 1 398 17OCT1997 02NOV1997 16 2 942 22JAN1998 10MAR1998 47 3 167 15DEC1999 15FEB2000 62 4 250 04JAN2001 11JAN2001 7 |
Boundaries of Intervals |
Example | Results | Explanation |
---|---|---|
mnthnum1= intck( 'month', '25aug2000'd, '05sep2000'd); |
mnthnum1=1 | The number of MONTH intervals the INTCK function counts depends on whether the first day of a month falls within the period. |
mnthnum2= intck( 'month', '01aug2000'd, '31aug2000'd); |
mnthnum2=0 | |
next=intnx( 'month', '25aug2000'd,1); |
next represents 01sep2000 | The INTNX function produces the SAS date value that corresponds to the beginning of the next interval. |
Note: The only intervals that do not begin
on the same date in each year are WEEK and WEEKDAY. A Sunday can occur on
any date because the year is not divided evenly into weeks.
Single-Unit Intervals |
Single-unit intervals begin at the following points on the calendar:
These single-unit intervals | Begin at this point on the calendar | |
---|---|---|
DAY and WEEKDAY | each day | |
WEEK | each Sunday | |
TENDAY | the first, eleventh, and twenty-first of each month | |
SEMIMONTH | the first and sixteenth of each month | |
MONTH | the first of each month | |
QTR | the first of January, April, July and October | |
SEMIYEAR | the first of January and July | |
YEAR | the first of January |
These single-unit time intervals | Begin at this point | |
---|---|---|
SECOND | each second | |
MINUTE | each minute | |
HOUR | each hour |
Multiunit Intervals |
For all multiunit intervals except multiweek intervals, the SAS System creates an interval beginning on January 1, 1960, and counts forward from that date to determine where individual intervals begin on the calendar. As a practical matter, when a year can be divided evenly by an interval, think of the intervals as beginning with the current year. Thus, MONTH2 intervals begin with January, March, May, July, September, and November. Consider this example:
SAS statements | Results | |
---|---|---|
howmany1=intck ('month2','15feb2000'd,'15mar2000'd); |
howmany1=1 |
|
count=intck ('day50','01oct2000'd,'01jan2000'd); |
count=1 |
SAS statements | Results | |
---|---|---|
start=intnx ('day50','01oct98'd,1); |
SAS date value 14200, or Nov 17, 1998 |
Time intervals (those that represent divisions of a
day) are aligned with the start of the day, that is, midnight. For example,
HOUR8 intervals divide the day into the periods 00:00 to 08:00, 8:00 to 16:00,
and 16:00 to 24:00 (the next midnight).
Calculating Multi Week Intervals
Therefore, the SAS System begins the first interval on Sunday of the week containing January 1, 1960--that is, on Sunday, December 27, 1959. The SAS System counts multiweek intervals from that point. The following example counts the number of two-week intervals in the month of August, 1998:
SAS statements | Results | |
---|---|---|
count=intck ('week2','01aug98'D, '31aug98'D); |
count=3 |
SAS statements | Results | |
---|---|---|
begin=intnx('week2','01aug1998'd,1); |
"Begin" represents SAS date 14093 or August 02, 1998 |
Shifted Intervals |
When you shift a time interval by a subperiod, the shift value must be less than or equal to the number of subperiods in the interval. For example, YEAR.12 is valid (yearly periods beginning in December), but YEAR.13 is not. Similarly, YEAR2.25 is not valid because there is no twenty-fifth month in the two-year period.
In addition, you cannot shift an interval by itself.
For example, you cannot shift the interval MONTH because the shifting subperiod
for MONTH is one month and MONTH contains only one monthly subperiod. However,
you can shift multi-unit intervals by the subperiod. For example, MONTH2.2
specifies bimonthly periods starting on the first day of the second month.
For all intervals except those based on weeks, the SAS System creates shifted intervals by creating the interval based on January 1, 1960, by moving forward the required number of subperiods, and by counting shifted intervals from that point. For example, suppose you create a shifted interval called DAY50.5. The SAS System creates a 50-day interval in which January 1, 1960 is day 1. The SAS System then moves forward to day 5. (Note that the difference, or amount of movement, is 4 days.) The SAS System begins counting shifted intervals from that point. The INTNX function demonstrates that the next interval begins on January 5, 1960:
SAS statements | Results | |
---|---|---|
start=intnx ('day50.5','01jan1960'd,1); |
SAS date value 4, or Jan 5, 1960 |
SAS statements | Results | |
---|---|---|
start=intnx ('week2.8','01jan1960'd,1); |
SAS date value 2, or Jan 3, 1960 |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.