## SAS Exponential Smoothing

Solved
Frequent Contributor
Posts: 118

# SAS Exponential Smoothing

Hi,

I have the following dataset (Table A)

Factory | Item |  Date           |  Actual_Demand

-------------------------------------------------------------

A       |  1     |2013-05-01  |  21

-------------------------------------------------------------

A       |  1     |2013-05-02  |  19

......           ....     .................      .....

-------------------------------------------------------------

A       |  1     |2017-04-30  |  15

......         ....       .................      ......

So for each combination of 'Factory' and 'Item', we have got actual demand for 4 years.

And I want to forecast future demand by 'Factory' and 'Item' level. Use the first 3-year data as training, and the last year data for testing. And I want to try 'exponential smoothing' method. How could I write the code? Will 'Proc Esm' help?

Thank you!

Accepted Solutions
Solution
‎05-11-2017 01:34 PM
SAS Employee
Posts: 27

## Re: SAS Exponential Smoothing

You can use the BACK= option in the PROC ESM statement to indicate the number of observations to withhold from the end of each series for model estimation.  The BACK= value will be applied to each BY group defined by the combination of values of your FACTORY and ITEM variables.  The LEAD= value specifies the number of multistep forecasts to compute and is relative to the BACK= specification.  When the BACK= option is used, the multistep forecasts begin at observation (n - back ) within each BY group.

For simplicity, let's assume you have 4 years of monthly data rather than daily data and you want to withhold the last 12 months of historical data from each series (ie. BY group) .  Suppose you then want multistep forecasts for these 12 values plus another year of forecasts.  To do this, you can specify the following in PROC ESM:

``````proc esm data=factory back=12 lead=24 outfor=fcst outest=est outstat=stat
print=all plot=modelforecasts;
by factory item;
id date interval=month;
forecast demand / model=damptrend;
run;

proc print data=fcst;
run;``````

This fits a DAMPTREND model, but you can specify your desired exponential smoothing model via the MODEL= option in the FORECAST statement.

By default, PROC ESM does not produce any output, however, I added the PRINT=ALL option to display the Statistics of Fit computed over the first 36 observations used to estimate the model, and the Performance Statistics computed over the region defined by the BACK= option for each series.  I also added the PLOT=MODELFORECASTS to view a plot of the one-step ahead predictions and multistep forecasts for each series.

You can apply this same concept to your daily data.  Note that if your daily Factory data does not include values for Saturday and Sunday, then you can use INTERVAL=WEEKDAY in the ID statement rather than INTERVAL=DAY.

I hope this helps!

All Replies
Solution
‎05-11-2017 01:34 PM
SAS Employee
Posts: 27

## Re: SAS Exponential Smoothing

You can use the BACK= option in the PROC ESM statement to indicate the number of observations to withhold from the end of each series for model estimation.  The BACK= value will be applied to each BY group defined by the combination of values of your FACTORY and ITEM variables.  The LEAD= value specifies the number of multistep forecasts to compute and is relative to the BACK= specification.  When the BACK= option is used, the multistep forecasts begin at observation (n - back ) within each BY group.

For simplicity, let's assume you have 4 years of monthly data rather than daily data and you want to withhold the last 12 months of historical data from each series (ie. BY group) .  Suppose you then want multistep forecasts for these 12 values plus another year of forecasts.  To do this, you can specify the following in PROC ESM:

``````proc esm data=factory back=12 lead=24 outfor=fcst outest=est outstat=stat
print=all plot=modelforecasts;
by factory item;
id date interval=month;
forecast demand / model=damptrend;
run;

proc print data=fcst;
run;``````

This fits a DAMPTREND model, but you can specify your desired exponential smoothing model via the MODEL= option in the FORECAST statement.

By default, PROC ESM does not produce any output, however, I added the PRINT=ALL option to display the Statistics of Fit computed over the first 36 observations used to estimate the model, and the Performance Statistics computed over the region defined by the BACK= option for each series.  I also added the PLOT=MODELFORECASTS to view a plot of the one-step ahead predictions and multistep forecasts for each series.

You can apply this same concept to your daily data.  Note that if your daily Factory data does not include values for Saturday and Sunday, then you can use INTERVAL=WEEKDAY in the ID statement rather than INTERVAL=DAY.

I hope this helps!

Frequent Contributor
Posts: 118

## Re: SAS Exponential Smoothing

[ Edited ]

Hi,

Thank you! It is pretty clear and I appreciate.

If I would like to forecast 1-year daily data (assuming weekend has demand), shall I make some changes to theparameter of your code?

``````proc esm data=factory back=365 lead=730 outfor=fcst outest=est outstat=stat
print=all plot=modelforecasts;
by factory item;
id date interval=day;
forecast demand / model=damptrend;
run;``````

It seems error message shows: Back = 365 is greater than the number of Time Series Value Thanks

SAS Employee
Posts: 27

## Re: SAS Exponential Smoothing

Hi Crubal,

I'm glad the information was helpful!  Given your desired analysis and the frequency of your data, the revised code look look fine.  I included the OUTEST= and OUTSTAT= options in case you wanted to create SAS data sets that contain the parameter estimates and fit statistics.  If these are not needed, then you can omit these options.  If you do not want the procedure to generate any output, then you can omit the PRINT= and PLOT= options as well.  You likely will want a SAS data set that contains the actuals, forecasts, standard errors and confidence limits for each series.  These are all included in the OUTFOR= data set.

I hope this helps!

DW

Frequent Contributor
Posts: 118

## Re: SAS Exponential Smoothing

Hi DW,

Thank you, as you mentioned it works thanks for your recommendation! I did try on 'Proc Forecast' functon like below using Exponential Smoothing, will that

``````proc forecast data=factory interval=day               method = Expo               lead = 365               out = fcst outest=est
by factory item;
id date;
var demand; where Date between '01MAY2013'd and '30APR2016'd;
run;
``````

Will that result the same? And by the way, is there any change that I could make for the 'Method = ' part so that I could use empirical mean to represent future date demand?

Thanks!

SAS Employee
Posts: 27

## Re: SAS Exponential Smoothing

Hi Crubal,

Regarding your question on PROC FORECAST, the ESM procedure optimizes the smoothing weights for the specified exponential smoothing model, but PROC FORECAST does not.  Because of this, I would strongly encourage you to use PROC ESM rather than PROC FORECAST.  (The FORECAST procedure is considered to be obsolete.)

If you want to fit an ESM where the multistep ahead forecasts are constant, then you might want to use the MODEL=SIMPLE on the FORECAST statement in PROC ESM.  For this model, the multistep forecasts equal the final smoothed value of the Level component.  For more details on the models supported by PROC ESM, please see the following documentation link:

http://support.sas.com/documentation/cdl/en/etsug/68148/HTML/default/viewer.htm#etsug_tffordet_sect0...

I hope this helps!

DW

Frequent Contributor
Posts: 118

## Re: SAS Exponential Smoothing

Hi DW,

Thanks! I will take a look at the link.

By the way, using 'Proc ESM' and model = damptrend,  future demand always gets the same, is it always the case from 'Exponential Smoothing' point of view?

Thank you!

Chenxi

SAS Employee
Posts: 27

## Re: SAS Exponential Smoothing

Hi Chenxi,

If you specify the MODEL=DAMPTREND option in PROC ESM, then the LEAD= forecast will not always be the same.  The behavior you observed is entirely data dependent.  I suspect the final smoothed trend for your data approximates 0.  To see the final smoothed trend, you can modify the PRINT= option in your code from PRINT=ALL to PRINT=(ALL STATES).  See also the k-step prediction equation for the Damped-Trend Linear Exponential Smoothing model in the link provided in my earlier reply for details on how the multistep forecasts are produced.

I hope this helps!

DW

☑ This topic is solved.