Returns the number of interval boundaries of a given kind that lie between two dates, times, or datetime values.
Category: | Date and Time |
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 Intervals Used with Date and Time Functions 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 a user-defined interval that is defined by a SAS data set. Each observation contains two variables, begin and end.
Requirement | You must use the INTERVALDS system option if you use the custom-interval variable. |
See | Details for more information about custom intervals. |
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 entire 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. For example, the interval name MONTH2.2 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 the starting SAS date, time, or datetime value.
specifies a SAS expression that represents the ending SAS date, time, or datetime value.
specifies that intervals are counted using either a discrete or a continuous method.
specifies that continuous time is measured. The interval is shifted based on the starting date.
data b;
WeddingDay='14feb2000'd;
Today=today();
YearsMarried=INTCK('YEAR',WeddingDay,today(),'C');
format WeddingDay Today date9.;
run;
proc print data=b;
run;
Alias | C or CONT |
specifies that discrete time is measured. The discrete method counts interval boundaries (for example, end of month).
Alias | D or DISC |
Default | DISCRETE |
intck('qtr','14JAN2005'd,'02SEP2005'd);
,
the start-date ('14JAN2005'd)
is equivalent to the first quarter of 2005. The end-date ('02SEP2005'd)
is equivalent to the third quarter of 2005. The interval count, that
is, the number of times the beginning of an interval is reached in
moving from the start-date to
the end-date is 2.
options intervalds=(interval=libref.dataset-name);
data a; interval='month'; start='14FEB2000'd; end='13MAR2000'd; months_default=intck(interval, start, end); months_discrete=intck(interval, start, end,'d'); months_continuous=intck(interval, start, end,'c'); output; end='14MAR2000'd; months_default=intck(interval, start, end); months_discrete=intck(interval, start, end,'d'); months_continuous=intck(interval, start, end,'c'); output; start='31JAN2000'd; end='01FEB2000'd; months_default=intck(interval, start, end); months_discrete=intck(interval, start, end,'d'); months_continuous=intck(interval, start, end,'c'); output; format start end date.; run; proc print data=a; run;