"It's Not funny!"
A very nice Chinese lady once asked me "Can you save the Kennedy Space Center?" I replied with the only response possible for a true SAS Professional.. An explanation of how to forecast using exponential smoothing models within Base SAS!
I guess this is why I still live with my parents.
I guess this is why I still live with my parents.
/* How to do Smoothing in SAS*/
There are 5 steps:
1. Sort your data so they are in line-date order
2. Specify the type of smoothing model you want with proc hpfesmspec
3. Select the smoothing model(s) you want to use with proc hpfselect
4. Create a forecast with your selected smoothing model(s) using proc hpfengine
5. Pray.
proc sort data=frozen_sample out=frozenSampleSort;
by customer linenum dow date;
run;
There are many ways to Smooth. Some popular techniques are Simple, Double and Winters. The basic smoothing technique is called ‘Simple’ in SAS. proc hpfesmspec is where we define the type of smoothing we want to use.
This is also the place where we can tell SAS to automatically choose the best smoothing weights for us, or used a fixed weight.
proc hpfesmspec repository = work.model *where the model will be saved;
specname = Simple; *the name of your model;
esm method = Simple; *the smoothing model;
run;
Add this code after the 'esm method = Simple' to use a fixed smoothing weight:
levelrest = (0,1) levelparm = "insert smoothing weight here" noest
- Select the model(s) you want to use.
Now that you’ve physically saved your model(s) the next step is to load them into memory (kind of like what happens with macro variables). You do this by creating a virtual folder, and putting all the models you want to use into it. In the next step you will point to this virtual folder as the location that contains all the models you want to use.
proc hpfselect repository = work.model *where the model(s) were saved;
name = myselect; *Name of the virtual folder;
spec simple; *The name of the model(s) you want to use;
run;
- Create a forecast with your selected model, Finally!
hpfengine is the step that actually generates the forecast. There are many options, a few important ones have been included.
proc hpfengine data = frozenSampleSort *sorted dataset;
outfor=WeekForecast *save just the forecast;
outest=WeekEst *save just the smoothing weights;
outstat=WeekStat *save just the statistics;
out=WeekData *save everything;
repository = work.model *location of models;
globalselection = myselect *location of virtual folder;
back = 0 *hides last x actual from forecast;
lead = 4 ; *forecasts y periods ahead;
by customer linenum dow; *by variable;
id date interval=day; *time between observations;
forecast weekdemand; *forecast variable;
run;
5. Hu Yu Hai Ding? Tai Ni Po Ni.
Do let me know if you have any questions, until next time SAS fans!
Thanks, Cannot use in my project, because have no control of the initial point estimate. According to sas Smoothing State Initialization
ReplyDeleteGiven a time series {Yt
: 1 ≤ t ≤ n}, the smoothing process first computes the
smoothing state for time t = 1. However, this computation requires an initial estimate of the smoothing state at time t = 0, even though no data exists at or before
time t = 0.
An appropriate choice for the initial smoothing state is made by backcasting from
time t = n to t = 1 to obtain a prediction at t = 0. The initialization for the backcast is obtained by regression with constant and linear terms and seasonal dummies
(additive or multiplicative) as appropriate for the smoothing model. For models with
linear or seasonal terms, the estimates obtained by the regression are used for initial
smoothed trend and seasonal factors; however, the initial smoothed level for backcasting is always set to the last observation, Yn.
The smoothing state at time t = 0 obtained from the backcast is used to initialize the
smoothing process from time t = 1 to t = n (refer to Chatfield and Yar 1988).
http://support.sas.com/documentation/onlinedoc/91pdf/sasdoc_913/hp_ug_9794.pdf
I'm using SAS 9.3 and when I run the 2nd step, I get the following error:
ReplyDelete"ERROR: Procedure HPFESMSPEC not found."
Any idea why that would happen?
Thanks