TSMODEL Procedure
ID Statement
ID variable INTERVAL=interval <options>;
The ID statement names a numeric variable that identifies the temporal order (time sequence) of observations in the input and output tables. The values of variables are assumed to be SAS date, SAS datetime, or observation values. In addition, the ID statement specifies the frequency to be associated with the time series. The ID statement options also specify a global treatment for how the time series variables are accumulated from the BY group’s rows and how the time ID values are aligned to form the time series. The specified information affects all variables that are specified in subsequent VAR statements. The ID statement and the INTERVAL= option are required to specify the desired accumulation frequency.
You must specify the following option:
- INTERVAL=interval
-
specifies the frequency of the accumulated time series. For example, if the input table consists of quarterly observations, then specify INTERVAL=QTR.
Interval names are constructed from a basic interval type with an optional multiplier and shift. The general form of an interval name is as follows:
type<multiplier>.<shift>
The interval type for SAS date values are summarized as follows:
- YEAR
specifies yearly intervals. Abbreviations are YEAR, YEARS, YEARLY, YR, ANNUAL, ANNUALLY, and ANNUALS. The starting subperiod shift is in months (MONTH).
- YEARV
specifies ISO 8601 yearly intervals. The ISO 8601 year starts on the Monday immediately preceding January 4 (or on January 4 if it is a Monday). Note that it is possible for the ISO 8601 year to start in December of the preceding year. Also, some ISO 8601 years contain a leap week. For more information about ISO weeks, see Technical Committee ISO/TC 154 (Processes, Data Elements, and Documents in Commerce, Industry, and Administration) (2004). The starting subperiod shift is in ISO 8601 weeks (WEEKV).
- R445YR
is the same as YEARV except that the starting subperiod shift is in retail 4-4-5 months (R445MON).
- R454YR
is the same as YEARV except that the starting subperiod shift is in retail 4-5-4 months (R454MON). For more information about the retail 4-5-4 calendar, see National Retail Federation (2007).
- R544YR
is the same as YEARV except that the starting subperiod shift is in retail 5-4-4 months (R544MON).
- SEMIYEAR
-
specifies semiannual intervals (every six months). Abbreviations are SEMIYEAR, SEMIYEARS, SEMIYEARLY, SEMIYR, SEMIANNUAL, and SEMIANN.
The starting subperiod shift is in months (MONTH). For example, SEMIYEAR.3 intervals are March–August and September–February.
- QTR
specifies quarterly intervals (every three months). Abbreviations are QTR, QUARTER, QUARTERS, QUARTERLY, QTRLY, and QTRS. The starting subperiod shift is in months (MONTH).
- R445QTR
specifies retail 4-4-5 quarterly intervals (every 13 ISO 8601 weeks). Some fourth quarters contain a leap week. The starting subperiod shift is in retail 4-4-5 months (R445MON).
- R454QTR
specifies retail 4-5-4 quarterly intervals (every 13 ISO 8601 weeks). Some fourth quarters contain a leap week. For more information about the retail 4-5-4 calendar, see National Retail Federation (2007). The starting subperiod shift is in retail 4-5-4 months (R454MON).
- R544QTR
specifies retail 5-4-4 quarterly intervals (every 13 ISO 8601 weeks). Some fourth quarters contain a leap week. The starting subperiod shift is in retail 5-4-4 months (R544MON).
- MONTH
specifies monthly intervals. Abbreviations are MONTH, MONTHS, MONTHLY, and MON. The starting subperiod shift is in months (MONTH). For example, MONTH2.2 intervals are February–March, April–May, June–July, August–September, October–November, and December–January of the following year.
- R445MON
specifies retail 4-4-5 monthly intervals. The 3rd, 6th, 9th, and 12th months are five ISO 8601 weeks long with the exception that some 12th months contain leap weeks. All other months are four ISO 8601 weeks long. R445MON intervals begin with the 1st, 5th, 9th, 14th, 18th, 22nd, 27th, 31st, 35th, 40th, 44th, and 48th weeks of the ISO year. The starting subperiod shift is in retail 4-4-5 months (R445MON).
- R454MON
specifies retail 4-5-4 monthly intervals. The 2nd, 5th, 8th, and 11th months are five ISO 8601 weeks long. All other months are four ISO 8601 weeks long with the exception that some 12th months contain leap weeks. R454MON intervals begin with the 1st, 5th, 10th, 14th, 18th, 23rd, 27th, 31st, 36th, 40th, 44th, and 49th weeks of the ISO year. For more information about the retail 4-5-4 calendar, see National Retail Federation (2007). The starting subperiod shift is in retail 4-5-4 months (R454MON).
- R544MON
specifies retail 5-4-4 monthly intervals. The 1st, 4th, 7th, and 10th months are five ISO 8601 weeks long. All other months are four ISO 8601 weeks long with the exception that some 12th months contain leap weeks. R544MON intervals begin with the 1st, 6th, 10th, 14th, 19th, 23rd, 27th, 32nd, 36th, 40th, 45th, and 49th weeks of the ISO year. The starting subperiod shift is in retail 5-4-4 months (R544MON).
- SEMIMONTH
specifies semimonthly intervals. SEMIMONTH breaks each month into two periods, starting on the 1st and 16th days. Abbreviations are SEMIMONTH, SEMIMONTHS, SEMIMONTHLY, and SEMIMON. The starting subperiod shift is in SEMIMONTH periods. For example, SEMIMONTH2.2 specifies intervals from the 16th of one month through the 15th of the next month.
- TENDAY
specifies 10-day intervals. TENDAY breaks the month into three periods, the 1st through the 10th day of the month, the 11th through the 20th day of the month, and the remainder of the month. (TENDAY is a special interval typically used for reporting automobile sales data.) The starting subperiod shift is in TENDAY periods. For example, TENDAY4.2 defines 40-day periods that start at the second TENDAY period.
- WEEK
specifies weekly intervals of seven days. Abbreviations are WEEK, WEEKS, and WEEKLY. The starting subperiod shift is in days (DAY), with the days of the week numbered as 1=Sunday, 2=Monday, 3=Tuesday, 4=Wednesday, 5=Thursday, 6=Friday, and 7=Saturday. For example, WEEK.7 means weekly with Saturday as the first day of the week.
- WEEKV
specifies ISO 8601 weekly intervals of seven days. Each week starts on Monday. The starting subperiod shift is in days (DAY). Note that WEEKV differs from WEEK in that WEEKV.1 starts on Monday, WEEKV.2 starts on Tuesday, and so on.
-
WEEKDAY
WEEKDAYdW
WEEKDAYddW
WEEKDAYdddW -
specifies daily intervals with weekend days included in the preceding weekday. Note that for a five-day work week that starts on Monday, the appropriate interval is WEEKDAY5.2. Abbreviations are WEEKDAY and WEEKDAYS. The starting subperiod shift is in weekdays (WEEKDAY).
The WEEKDAY interval is the same as DAY except that weekend days are absorbed into the preceding weekday. Thus, there are five WEEKDAY intervals in a calendar week: Monday, Tuesday, Wednesday, Thursday, and the three-day period Friday-Saturday-Sunday.
The default weekend days are Saturday and Sunday, but any one to six weekend days can be listed after the WEEKDAY string and followed by a W. Weekend days are specified as '1' for Sunday, '2' for Monday, and so forth. For example, WEEKDAY67W specifies a Friday-Saturday weekend. WEEKDAY1W specifies a six-day work week with a Sunday weekend. WEEKDAY17W is the same as WEEKDAY.
- DAY
specifies daily intervals. Abbreviations are DAY, DAYS, and DAILY. The starting subperiod shift is in days (DAY).
The interval type for SAS datetime values are summarized as follows:
- DTSAS-date-interval
specifies a SAS datetime interval that corresponds to the SAS date interval but operates on SAS datetime values. The SAS datetime interval is created by adding the prefix "DT" to the SAS date interval name. For example, DTMONTH.
- HOUR
specifies hourly intervals. Aliases are HOUR, DTHOUR, HOURS, DTHOURS, HOURLY, DTHOURLY, HR, and DTHR. The starting subperiod shift is in hours (HOUR).
- MINUTE
specifies minute intervals. Aliases are MINUTE, DTMINUTE, MINUTES, DTMINUTES, MIN, and DTMIN. The starting subperiod shift is in minutes (MINUTE).
- SECOND
specifies second intervals. Aliases are SECOND, DTSECOND, SECONDS, DTSECONDS, SEC, and DTSEC. The starting subperiod shift is in seconds (SECOND).
The interval type for SAS observation values is summarized as follows:
-
OBS
n specifies that observation numbers identify the time periods. You can specify INTERVAL=n as an alias for INTERVAL=OBSn.
If the SEASONALITY= option is not specified in the PROC TSMODEL statement, then the length of the seasonal cycle is implied by the INTERVAL= option. For example, INTERVAL=QTR implies a seasonal cycle of length 4. For more information about seasonality, see the section "Seasonality in Models" in Chapter 17, Forecasting Details (SAS Visual Forecasting: Time Series Packages).
You can also specify the following options:
- ACCUMULATE=option
-
specifies how to accumulate the table observations within each time period into a single value. The frequency (width of each time interval) is specified in the INTERVAL= option. The ID variable contains the time ID values. The value of the time ID variable identifies the time period of the observation. The accumulated values for each time period form the time series, which is used in subsequent analysis.
The ACCUMULATE= option is necessary when multiple input observations identify the same time period. An example of this is timestamped transactional data.
The following options determine how to accumulate the observations within each time period based on the ID variable and the frequency specified by the INTERVAL= option. Each value indicates how the accumulated value is calculated:
- TOTAL | SUM
calculates as the total sum of the nonmissing values.
- AVERAGE | AVG
calculates as the average of the nonmissing values.
- MINIMUM | MIN
calculates as the minimum of the nonmissing values.
- MAXIMUM | MAX
calculates as the maximum of the nonmissing values.
- N
calculates as the number of nonmissing observations.
- NMISS
calculates as the number of missing observations.
- STDDEV | STD
calculates as the standard deviation of the nonmissing values.
- CSS
calculates as the corrected sum of squares of the nonmissing values.
- USS
calculates as the uncorrected sum of squares of the nonmissing values.
By default, ACCUMULATE=TOTAL.
The SETMISSING= option is useful for specifying how to treat missing values in the accumulated time series variable. If missing values should be interpreted as 0, then specify SETMISSING=0. For more information about accumulation, see the section Accumulation.
- ALIGN=option
-
controls the alignment of SAS date or datetime values that are used to identify the time period of output observations. Although any date or datetime value within the time period can identify the time period, the ALIGN= option requests that the representative date or datetime for the time period be calculated as the beginning date or datetime of the time period, the ending date or datetime of the time period, or the middle date or datetime of the time period. In addition to aligning the time ID values consistently for observations that are supplied by the user, the ALIGN= option specifies the method for calculating the time ID values for observations in the forecast and backcast time periods, which often are not supplied by the user. You can specify the following options:
- BEGINNING | BEG | B
represents each time period using the beginning SAS date or datetime value of the time period.
- ENDING | END | E
represents each time period using the ending SAS date or datetime value of the time period.
- MIDDLE | MID | M
represents each time period using the middle SAS date or datetime value of the time period. The middle is calculated as the average of the beginning and ending values.
By default, ALIGN=BEGINNING.
- DISTRIBUTE=option
-
specifies the method that is used to distribute the input time series observations in the input tables across the CAS worker nodes in the CAS session. This process, which is known as "autopartitioning," is performed in order to form complete time series that are suitable for processing. You can specify the following options:
- AUTO
automatically selects the best approach, using either the PREACCUMULATE or SHUFFLE option, to distribute the input time series observations across the CAS worker nodes in the CAS session. The selection occurs on the basis of both the accumulation time interval that you specify in the INTERVAL= option and the level of scattering of the time series observations across the CAS worker nodes.
- PREACCUMULATE | PREACC
generates partially accumulated time series (that is, those that have a fixed length and a fixed interval) on each CAS worker node in the CAS session and then distributes their observations to their destination CAS worker nodes. These partially accumulated time series are accumulated again upon arrival at their destination CAS worker nodes in order to form complete time series. This option can usually reduce the amount of time that is required in order to distribute time series observations across the CAS worker nodes, especially in the case in which you specify an accumulation interval in the INTERVAL= option that is larger than the natural frequency of the input data. However, this option can require additional memory in order to generate the partially accumulated time series on the CAS worker nodes.
- SHUFFLE
distributes the raw time series observations to their destination CAS worker nodes in the CAS session before accumulating them into complete time series. This option is recommended when you specify an accumulation time interval in the INTERVAL= option that is close to the natural frequency of the input data. This option requires less memory than the PREACCUMULATE option because it does not have to generate partially accumulated time series in the memory of each CAS worker node. However, this option can lead to a longer run time than the PREACCUMULATE option when it is used outside the recommended setting.
By default, DISTRIBUTE=AUTO.
- END=value
specifies a SAS date or datetime value that represents the end of the data. If the last time ID variable value is less than value, then the series is extended with missing values. If the last time ID variable value is greater than value, then the series is truncated. For example, END="&sysdate"D uses the automatic macro variable SYSDATE to extend or truncate the series to the current date. You can specify the START= and END= options to ensure that the data that are associated within each BY group contain the same number of observations.
- FORMAT=format
specifies the SAS format for the time ID values. If this option is omitted, then the default format is inferred from the INTERVAL= option. You can specify FORMAT=_DATA_ to force the SAS format of the time ID variable to be automatically propagated to the time ID values.
- NLFORMAT=option
-
enables the selection of the best international SAS format for the time ID values on the basis of the accumulation time interval that you specify in the INTERVAL= option. This option is ignored when you specify the FORMAT= option. You can specify the following options:
- NO
selects the best English-language-based SAS format for the time ID values.
- YES
selects the best international SAS format for the time ID values.
By default, NLFORMAT=NO.
- SETMISSING=option
-
specifies how to interpret missing values (either actual or accumulated) in the accumulated time series. You can use the following options to determine how to interpret missing values:
- n
interprets a missing value as having the value n. You can specify any number for n, but not a missing value. If a missing value indicates a 0 value, specify SETMISSING=0. You typically use SETMISSING=0 for transactional data because no recorded data usually implies no activity.
- MISSING
interprets a missing value as a missing value. Use this option if a missing value indicates an unknown value.
- AVERAGE | AVG
interprets a missing value as the average value of all accumulated nonmissing values in the span of the series.
- MINIMUM | MIN
interprets a missing value as the minimum value of all accumulated nonmissing values in the span of the series.
- MEDIAN | MED
interprets a missing value as the median value of all accumulated nonmissing values in the span of the series.
- MAXIMUM | MAX
interprets a missing value as the maximum value of all accumulated nonmissing values in the span of the series.
- FIRST
interprets a missing value as the first nonmissing value of all accumulated nonmissing values in the span of the series.
- LAST
interprets a missing value as the last nonmissing value of all accumulated nonmissing values in the span of the series.
- PREVIOUS | PREV
interprets a missing value as the previous period’s accumulated nonmissing value. Missing values at the beginning of the accumulated series remain missing.
- NEXT
interprets a missing value as the next period’s accumulated nonmissing value. Missing values at the end of the accumulated series remain missing.
By default, SETMISSING=MISSING.
- START=value
specifies a SAS date or datetime value that represents the beginning of the data. If the first time ID variable value is greater than value, then missing values are added at the beginning of the series. If the first time ID variable value is less than value, then the series is truncated. You can specify the START= and END= options to ensure that data associated with each BY group contain the same number of observations.
- TRIMID=method
-
specifies the method for trimming the data in the BY groups when time series vectors are input to the user-defined program. The output time ID variable span that is calculated by the method is dependent on the input time ID variable span, irrespective of missing values of the time series variables. Depending on the method and the input time ID variable data, leading or trailing missing values can be added to the time series variables.
After the output time ID variable span is calculated by the method, the ending value of the output time ID variable will be recalculated according to the value of the LEAD= option (if one is specified).
You can specify one of the following methods:
- NONE
uses the same starting and ending values of the output time ID variable for all BY groups. The span of the output time ID variable includes all values that are input as a time ID value for all BY groups. The time series variables are extended with leading or trailing missing values as required.
- LEFT
uses the identifying date for the first time period that is input for the BY group as the starting value of the output time ID variable for each BY group. The time series values in each BY group are not extended with leading missing values. The ending value of the time ID variable is the same for all BY groups. The time series variables are extended with trailing missing values as required.
- RIGHT
uses the identifying date for the last time period that is input for the BY group as the ending value of the output time ID variable for each BY group. The time series values in each BY group are not extended with trailing missing values. The starting value of the time ID variable is the same for all BY groups. The time series variables are extended with leading missing values as required.
- BOTH
uses the span of the input time ID variable for the BY group as the span of the output time ID variable for each BY group. The time series values in each BY group are not extended with leading or trailing missing values.
By default, TRIMID=NONE.
Note that when you do not specify the START= and END= options in the ID statement, the TSMODEL procedure is required to make an additional pass through the primary data set that you specified in the DATA= option in order to determine its time index span. This is required so that the total number of accumulation time intervals can be computed using the accumulation frequency that you specified in the INTERVAL= option. In this scenario, the TSMODEL procedure will read all rows from the primary data set exactly twice. Moreover, this effect will be captured in the numeric value associated with the row labeled 'Number of rows read' of the time series processing summary table that is generated at the end of the execution of the TSMODEL procedure, as is illustrated in Figure 1 and Output 29.1.1.