Read without ads and support Scribd by becoming a Scribd Premium Reader.
 
ST007
Basic Usage of SAS/ETS® Software to Forecast a Time Series
by LTC Douglas L. McAllasterUS Army Logistics Management College, Fort Lee, Virginia
ABSTRACTThis paper is a tutorial on using SAS/ETS to forecast atimes series. We explain how PROC FORECASTgenerates forecasts using the three main exponentialsmoothing methods (single, Holt's, & Winters') and thestepwise auto-regressive method. Next, we explain usageof PROC REG (or better, PROC AUTOREG) to forecasta seasonal times series using indicator variables. Finally,we briefly overview of the capabilities and complicationsof using PROC ARIMA.INTRODUCTIONForecasting a times series is the process of projecting atime series into the future. We can forecast two ways:either with extrapolation methods or with explanatorymodels. Extrapolation methods are adaptive techniqueswhich simply project the series by responsively smoothingrecently observed data. On the other hand, explanatorymodels attempt to fit the observed data to somemathematical model or underlying process.EDAExploratory data analysis (EDA) is the first and necessarystep for proper time series analysis. We look at a timesseries plot of the data to visually identify the presence of three possible components: level, trend, and seasonality.First, the plot may be flat, showing only randomfluctuation about some constant LEVEL. Second, the plotmay show an upward (or downward) TREND over time.Finally, the plot may show some obviousSEASONALITY. The various time series plots in theappendix display these components.EXPONENTIAL SMOOTHING IDEASExponential smoothing is the easiest and (thus?) the mostwidely used extrapolation method. The basic idea of thismethod is to project a series based mostly on recent data,i.e., without much regard to older data. We could call thisa "short memory" method. This makes good commonsense: we believe that sales next year depends much moreon sales last year than on the sales from ten or even fiveyears ago.Another idea inherent in exponential smoothing is that aforecast for next period should be based on the accuracyof the most recent forecast. That is, if our most recentforecast was too high, we adjust the next forecastdownward. Likewise, if our most recent forecast was toolow, we adjust the next forecast upwards. Thus, wedescribe smoothing methods as self-correcting, adaptive,and responsive; or, as we in the military like to say, a "fire& forget" weapon system. The appendix has plotsshowing the responsiveness of exponential smoothingtechniques vice the fixed line created by using aregression method.Furthermore, the short memory of exponential smoothingmakes it a particularly appropriate method when the timeseries components (level, trend, & seasonality) arechanging over time. Finally, the adaptive feature of smoothing methods is especially useful since an analystoften must forecast many dozens or hundreds of stock keeping units (SKUs) and does not want to manuallydetermine changes in direction or tailor a separate modelfor each SKU. Of course, the SAS System has BYvariable processing which makes for very simple coding,indeed.PROC FORECASTThere are three main exponential smoothing methods:single, Holt's, & Winters'. We choose the appropriatemethod according to the components we identified duringthe EDA phase. That is, we use single exponentialsmoothing for a series which has only the levelcomponent, Holt's exponential smoothing method for aseries which also has a trend component, and Winters'exponential smoothing method for a series which also hasa seasonal component.SESSingle exponential smoothing is (SES) the simplest of thethree main exponential smoothing methods, so we beginour explanation here. A perusal of the SES equation inthe appendix shows the above mentioned self-correctivenature of the method. (The second equation is moreconvenient for spreadsheet implementation.) Byconvention, Yt is the series value and Ft is a forecastvalue. The alpha factor smooths the level component of the series, i.e, smooths out the past forecast errors. Wecall alpha a "smoothing or dampening factor" rather than aparameter since, in this context, we are not fitting anexplanatory model to the data. Rather, we are simplyextrapolating the series, not trying to determine a formal
Statistics, Data Analysis & EconometricsNESUG 16
 
statistical parameter, like a beta in the familiar regressionmodel.SMOOTHING FACTORThe analyst must specify a smoothing factor for thismethod. This factor controls how much relative weightthe procedure gives to newer verses older data. Validfactors are between zero and unity. A factor near unitygives the vast majority of the weight to the most recentobservations whereas a factor nearer zero allows the olderobservations to influence the forecast. Typical values arebetween one-tenth and one-third.To determine a "good or best" smoothing factor, mosttexts recommend analysts use a trial & error approach tominimize some measure of inaccuracy, either absolute orsquared error. This is fairly easy with a well designedspreadsheet which permits dynamic adjustments of thesmoothing factor to see the impact the measures of accuracy. Currently, neither Microsoft® Excel nor PROCFORECAST automatically optimizes this factor tominimize squared error. Without an optimizationsubroutine, texts recommend that alpha should be no morethan 0.4, otherwise the analyst is probably using SES onan inappropriate series, i.e., on a series which has morethan the level component only. PROC FORECASTprovides a default smoothing factor if the analyst omits it.Some software packages automatically optimize thesmoothing factor, e.g., Minitab and some third party MSExcel add-ins. A future release of SAS/ETS software willinclude a PROC TREND which will automaticallyoptimize the smoothing factor. PROC TREND isexperimental in SAS version 8.1 (& omitted from the on-line documentation). My presentation will include samplePROC TREND code if SI will provide me somepreliminary documentation.HOLT'S METHODHolt extended (Brown's original) SES idea to smooth thetrend component as well as the level component. That is,Holt's method is the proper one when the series has boththe level & trend components. Thus, Holt's method hastwo dampening factors, often called alpha & beta. Alphasmooths the level component and beta smooths the trendcomponent. Again, the equations are in the appendix.The presentation of this paper will show MS Excelimplementations of both SES and Holt's methods. Thesetables are helpful to see the time series component partsand to understand what the smoothing equations aredoing.Unfortunately, there are no rules of thumb for "good"smoothing factors in Holt's method. Nevertheless, somestatistical software packages optimize these factors.WINTERS' METHODWinters' extended Holt's method to smooth the third andfinal component, seasonality. The equations (see theappendix) look a little scary and a spreadsheet version of this method is a bit cumbersome, so we omit it from thepresentation. However, once an analyst understands thesmoothing concept in Holt's, he should feed confident inusing Winters' method, i.e., without the "black box"syndrome.The appendix has documented examples of the codewhich produced the exponential smoothing forecasts(SES, Holt's, & Winters') shown. The options are a bittricky to get Holt's method: the analyst specifiesMETHOD=Winters BUT provides NO third (seasonal)smoothing factor NOR includes the SEASONS=monthoption.INITIALIZATIONAll of these exponential smoothing procedures requireinitialization. Typically, statistical software packagesperform a simple linear regression against the first fewobservations to produce an initial forecast of the level andtrend components. Thereafter, the exponential smoothingprocedure adjusts future forecasts based on the accuracyof the recent forecasts. Fortunately, forecasting is notsensitive to the initialization method as long as there areten or twenty observations, since exponential smoothinghas short memory.SAS provides various initialization options. The code inthe appendix bases the initial forecast on the first one(SES), two (Holt's), or season (Winters') of data by usingmacro variables to pass initial values derived from a datastep into the PROC FORECAST step. I use thisinitialization in teaching since it is easiest to implement ina spreadsheet and since exponential smoothing is robustwith respect to initialization.WHY NOT PROC REG?Neophyte analysts (and many experienced practitioners!)would probably apply ordinary least squares (OLS)regression to forecast a times series since every analystlearns (ok, studies) it. Actually, their results would bequite good, given a reasonable history of data and a seriesin which the level & trend components which are notchanging drastically. The plots in the appendix show theobvious faults of using OLS regression on series whosecomponents change significantly or on a series havingseasonality. Again, a strength of exponential smoothing is
Statistics, Data Analysis & EconometricsNESUG 16
 
its adaptability to changing components, i.e., its shortmemory.Of course, the analyst could make PROC REG responsiveto recent data by generating and applying increasinglylarge weights to recent observations. In fact, below wewill conclude that regression is indeed a good method,even despite the technical violation of the "independenceof errors" assumption.PROC REG & SEASONALITYNow, many analysts are also familiar with using indicator(binary) predictor variables in OLS regression. Analystsmight prefer to bypass Winters' method in favor of thisseasonal-indicator-variable OLS method as a very usefulalternative to model seasonal data. We proceed asfollows. We simply introduce eleven (seasonal) indicatorvariables to identify the month along with the timevariable to capture the trend component. The only realtrick is to first transform the original series by taking thenatural log of Y in order to dampen out the typicallyincreasing variance as time increases and then toexponentiate the forecasts to restore the original series.The appendix has a chart showing that OLS regression fitsseparate and parallel straight lines for each of the twelvemonths. (The 12th month is the one which has all elevenindicators variables equal to zero.) The appendix also hascharts showing the pitfall of performing the regressionwithout the log transformation.AUTO-CORRELATIONTime series data often exhibits something called auto-correlation. This means that observations are NOTindependent, one from another. Now, if the obs are notindependent, then neither will the residuals from OLSregression be independent. This dependency is a(technical) violation of the normal, independent,identically distributed (NII) assumption about residualsrequired by the OLS regression model.There are two types of auto-correlation: positive andnegative. Positive auto-correlation is more common inreal data. This means that errors tend to stay positive fora while then switch negative and stay negative for a whileand so on back and forth. Negative auto-correlation is notso easy to see on a plot and occurs when errors bounceback and forth between positive and negative too often.The Durbin-Watson statistic is a widely used but limiteddetector for auto-correlation. (PROC REG will calculateit upon request, by the DW option on the modelstatement.) The Durbin-Watson statistic is limited in thatit detects auto-correlation at lag 1 only. Nevertheless, lag1 correlation is the most common pattern in real data, soDW is a very useful diagnostic.PROC AUTOREGThe statistically correct method for handling auto-correlated data is to use the auto-regressive method. Thismethod accounts for the dependency with an additionalparameter to model the auto-correlation. SAS/ETSsoftware includes PROC AUTOREG to fit an auto-regressive model.Now, although times series often violate the independenceassumption, the forecasts using PROC REG would beabout the same as if one used PROC AUTOREG, as longas there is a reasonable history of data. The onlydisadvantage is that forecasts would not be as precise, i.e.,confidence intervals would be wider, since OLSregression does not model the errors as well as auto-regression. The SAS/ETS User's Guide chapter on PROCAUTOREG shows this via an informative example.Using PROC AUTOREG is very similar to using PROCREG, so many SAS data analysts will find moving toPROC AUTOREG an easy step. The only really newsyntax is the NLAG=# option. For example, if we specifyNLAG=5, PROC AUTOREG will fit five auto-regressiveparameters. Without the NLAG option PROCAUTOREG performs OLS regression.FORECAST VS AUTOREGNow, PROC FORECAST can also perform auto-regression. In fact, stepwise auto-regression is its defaultmethod. However, since most neophyte forecasters maynot have studied auto-regression, this default behavior isprobably not where the novice should begin. Thus,perhaps the main benefit of this paper is that it presentsforecasting in the typical learning sequence so the analystcan use the METHOD=stepar option without fear, asfollows.The METHOD=stepar option calculates good forecastswith minimal user input. That is, if the analyst understandsthat the procedure is simply a regression on time withadditional parameter(s) to model correlation of residualsat various lags, then he should feel comfortable using thestepwise auto-regression results. Perhaps the onlyconfusing thing is that the SEASONS=month options isnot valid with METHOD=stepar since this method usesonly time as the only predictor variable to detrend the dataand models all remaining variation with auto-regressive(error correlation) parameter(s).Syntax note. Although the procedure will fit somenumber of lags by default, correct BY variable processingrequires specifying it via an NLAGS=# option. Thus, Irecommend always specifying the number of correlationsto fit via the NLAGS=# option. Again, I suggest simplyspecifying one more lag than the seasonal period,12+1=13 for monthly data and 4+1=5 for quarterly data.
Statistics, Data Analysis & EconometricsNESUG 16
Search History:
Searching...
Result 00 of 00
00 results for result for
  • p.
  • Notes
    Load more