Increments a date, time, or datetime value by a given time interval, and returns a date, time, or datetime value.
Category: | Date and Time |
specifies a character constant, variable, or expression that contains a time interval such as WEEK, SEMIYEAR, QTR, or HOUR. 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.
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 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 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, 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 | Incrementing Dates and Times by Using Multipliers and by Shifting Intervals for more information. |
specifies a SAS expression that represents a SAS date, time, or datetime value that identifies a starting point.
specifies a negative, positive, or zero integer that represents the number of date, time, or datetime intervals. Increment is the number of intervals to shift the value of start-from.
controls the position of SAS dates within the interval. You must enclose alignment in quotation marks. Alignment can be one of these values:
specifies that the returned date or datetime value is aligned to the beginning of the interval.
Alias | B |
specifies that the returned date or datetime value is aligned to the midpoint of the interval, which is the average of the beginning and ending alignment values.
Alias | M |
specifies that the returned date or datetime value is aligned to the end of the interval.
Alias | E |
specifies that the date that is returned has the same alignment as the input date.
Aliases | S |
SAMEDAY | |
See | SAME Alignment for more information. |
Default | BEGINNING |
See | Aligning SAS Date Output within Its Intervals for more information. |
specifies an interval that you define.
x=intnx('week', '17oct03'd, 6); put x date9.;
data _null_; /* The following statement creates expected results. */ date1=intnx('dtday','01aug11:00:10:48'dt,1); /* The following two statements create unexpected results. */ date2=intnx('dtday','01aug11'd,1); date3=intnx('dtday','01aug11:00:10:48'd,1); put 'Correct Datetime Value ' date1= datetime19. / 'Incorrect Datetime Value ' date2= datetime19. / 'Incorrect Datetime Value ' date3= datetime19.; run;
intnx('month', '15mar2000'd, 5, 'same'); returns 15AUG2000 intnx('year', '29feb2000'd, 2, 'same'); returns 28FEB2002 intnx('month', '31aug2001'd, 1, 'same'); returns 30SEP2001 intnx('year', '01mar1999'd, 1, 'same'); returns 01MAR2000 (the first day of the third month of the year)
intnx('year',
'29feb2000'd, 2);
, the INTNX function returns the value
01JAN2002, which is the beginning of the year two years from the starting
date (2000).
intnx('year',
'29feb2000'd, 2, 'same');
, the INTNX function returns
the value 28FEB2002. In this case, the starting date begins in the
year 2000, the year is two years later (2002), the month is the same
(February), and the date is the 28th, because that is the closest
date to the 29th in February 2002.
options intervalds=(interval=libref.dataset-name);
options intervalds=(weekdaycust=dstest); data dstest; format begin end date9.; begin='01jan2008'd; end='01jan2008'd; output; begin='02jan2008'd; end='02jan2008'd; output; begin='03jan2008'd; end='03jan2008'd; output; begin='04jan2008'd; end='06jan2008'd; output; begin='07jan2008'd; end='07jan2008'd; output; begin='08jan2008'd; end='08jan2008'd; output; begin='09jan2008'd; end='09jan2008'd; output; begin='10jan2008'd; end='10jan2008'd; output; begin='11jan2008'd; end='13jan2008'd; output; begin='14jan2008'd; end='14jan2008'd; output; begin='15jan2008'd; end='15jan2008'd; output; run; data _null_; format start date9. endcustom date9.; start='01jan2008'd; do i=0 to 9; endcustom=intnx('weekdaycust', start, i); put endcustom; end; run;