Increments a SAS date, time, or datetime value encoded as a DOUBLE, and returns a SAS date, time, or datetime value encoded as a DOUBLE.
Category: | Date and Time |
Returned data type: | DOUBLE |
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:
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. |
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. |
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. |
specifies an expression that represents a SAS date, time, or datetime value encoded as a DOUBLE and that identifies a starting point.
Data type | DOUBLE |
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.
Data type | INTEGER |
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 |
Default | BEGINNING |
Data type | CHAR |
See | Aligning SAS Date Output within Its Intervals |
select put(intnx('week', date'2011-10-17', 6), date9.);
/*** returns 22MAR2011 ***/ select put(intnx('week', date'2011-03-15', 1, 'same'), date9.); /*** returns 15MAR2016 ***/ select put(intnx('year', date'2011-03-15', 5, 'same'), date9.);
/*** returns 15AUG2011 ***/ select put(intnx('month', date'2011-03-15', 5, 'same'), date9.); /*** returns 28FEB2014 ***/ select put(intnx('year', date'2012-02-29', 2, 'same'), date9.); /*** returns 30SEP2011 ***/ select put(intnx('month', date'2011-08-31', 1, 'same'), date9.); /*** returns 01MAR2012 (the 1st day of the 3rd month of the year) ***/ select put(intnx('year', date'2011-03-01', 1, 'same'), date9.); /*** returns 29FEB2012 (the 60th day of the year) ***/ select put(intnx('year', date'2011-03-01', 1, 'same', 'day'), date9.);
select put(intnx('year', date'2012-02-29', 2), date9.);
select put(intnx('year', date'2012-02-29', 2, 'same'), date9.);
Statements
|
Results
|
---|---|
select intnx('year', date'2013-02-05', 3); select put(intnx('year', date'2013-02-05', 3), date7.); |
20454 01Jan16 |
select intnx('month', date'2013-01-05', 0); select put(intnx('month', date'2013-01-05', 0), date7.); |
19359 01JAN13 |
select intnx('semiyear', date'2013-01-01', 1); select put(intnx('semiyear', date'2013-01-01', 1), date7.); |
19540 01JUL13 |
select intnx('month2', date'2012-08-01', -1); select put(intnx('month2', date'2012-08-01', -1), date7.); |
19114 01MAY12 |
select intnx('semimonth2.2', date'2013-04-01', 4); select put(intnx('semimonth2.2', date'2013-04-01', 4), date7.); |
19555 16JUL13 |
Statements
|
Results
|
---|---|
select intnx('month', date'2013-01-01', 5, 'beginning'); select put(intnx('month', date'2013-01-01', 5, 'beginning'), date7.); |
19510 01JUN13 |
select intnx('month', date'2013-01-01', 5, 'middle'); select put(intnx('month', date'2013-01-01', 5, 'middle'), date7.); |
19524 15JUN13 |
select intnx('month', date'2013-01-01', 5, 'end'); select put(intnx('month', date'2013-01-01', 5, 'end'), date7.); |
19539 30JUN13 |
select intnx('month', date'2013-01-01', 5, 'sameday'); select put(intnx('month', date'2013-01-01', 5, 'sameday'), date7.); |
19510 01JUN13 |
select intnx('month', date'2013-03-15', 5, 'same'); select put(intnx('month', date'2013-03-15', 5, 'same'), date7.); |
19585 15AUG13 |