BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Dwayne
Fluorite | Level 6

I’m currently using PROC ESM for exponential smoothing modeling using Holt-Winters “Additive” type methods for time series data sets with (and without) trend and with (and without) seasonality.


Question: Is there an ESM option (or another procedure) that will print out the “back-casting” details in a similar manner as with using the ESM’s “print=forecast” option?


For no-trend (model=simple) and no-trend w/seasonality (model=addseasonal), my EXCEL calculations always match the back-casting “state” values that I get from my SAS program. However, when I add a trend component to the model, my “final” back-casting state values no longer match – even assuming the same alpha, gamma and delta parameters, and starting values as SAS. I’ve already read the “Smoothing State Initialization” documentation.

 

My Code:

proc esm data=a print=(estimates forecasts performance statistics states) printdetails
lead=1
out=out_a outest=outest_a outfor=outfor_a outstat=outstat_a;
forecast customers / model=linear;
title3 'ESM Procedure';
run;

 

State           Level              Trend

Backcast    4,021              185.963235

Starting         810.20902   185.832622

Final           3,990.30259   185.849896

 

Using the above example for reference, what I need to see is SAS’s calculation flow from the initial Backcast state (4021/185.963235) to the “starting” forward’s modeling values at t=0 (810.20902/185.832622).


Thanks in advance!

 

1 ACCEPTED SOLUTION

Accepted Solutions
dw_sas
SAS Employee

Hi Dwayne,

 

PROC ESM does not provide a way to output the backcast values used to obtain the Starting Level and Trend values for the Linear exponential smoothing model, however, the smoothing calculations for the backcasts are essentially the same as the smoothing calculations for the "forwards casting".  These smoothing calculations are described in the following section of the SAS/ETS User's Guide:

 

Equations for the Smoothing Models:

https://go.documentation.sas.com/?docsetId=etsug&docsetTarget=etsug_tffordet_sect021.htm&docsetVersi...

 

Please note, however, that for backcasting, the sign of the initial trend parameter is reversed, since the series is sorted in reverse order.  Following, please find a description of the methodology used to compute the backcasts for MODEL=LINEAR in PROC ESM:

 

1)  Add a time trend variable to the original data set, for example, "t", which is simply the observation number 1, 2, ..., n.

2)  Obtain the initial Level and Slope values:

  • Initial Level is the value of the last observation in the data set
  • Initial Slope is the negative of the slope coefficient from regressing the time series variable on a time trend variable (ie. 1, 2,...n)

3) Sort the data, descending, by the time trend variable.

4) Backcast using the reverse-ordered data:

  • level [1] is:  alpha*y[1] + (1-alpha)*(initial level + initial trend)
  • trend [1] is:  gamma*(level[1] - initial level) + (1-gamma)*initial trend

5) Continue with smoothing computations through reverse ordered series using the equations noted in the above link.

6)  To obtain the Starting Level and Trend values from the backcasts, go to the last observation from step 5)

  •  Starting_level = Level[n] + Trend[n] (from step 5)
  •  Starting_trend = -Trend[n] (from step 5);

 

I hope this description helps, Dwayne!

DW

 

 

 

View solution in original post

10 REPLIES 10
dw_sas
SAS Employee

Hi Dwayne,

 

PROC ESM does not provide a way to output the backcast values used to obtain the Starting Level and Trend values for the Linear exponential smoothing model, however, the smoothing calculations for the backcasts are essentially the same as the smoothing calculations for the "forwards casting".  These smoothing calculations are described in the following section of the SAS/ETS User's Guide:

 

Equations for the Smoothing Models:

https://go.documentation.sas.com/?docsetId=etsug&docsetTarget=etsug_tffordet_sect021.htm&docsetVersi...

 

Please note, however, that for backcasting, the sign of the initial trend parameter is reversed, since the series is sorted in reverse order.  Following, please find a description of the methodology used to compute the backcasts for MODEL=LINEAR in PROC ESM:

 

1)  Add a time trend variable to the original data set, for example, "t", which is simply the observation number 1, 2, ..., n.

2)  Obtain the initial Level and Slope values:

  • Initial Level is the value of the last observation in the data set
  • Initial Slope is the negative of the slope coefficient from regressing the time series variable on a time trend variable (ie. 1, 2,...n)

3) Sort the data, descending, by the time trend variable.

4) Backcast using the reverse-ordered data:

  • level [1] is:  alpha*y[1] + (1-alpha)*(initial level + initial trend)
  • trend [1] is:  gamma*(level[1] - initial level) + (1-gamma)*initial trend

5) Continue with smoothing computations through reverse ordered series using the equations noted in the above link.

6)  To obtain the Starting Level and Trend values from the backcasts, go to the last observation from step 5)

  •  Starting_level = Level[n] + Trend[n] (from step 5)
  •  Starting_trend = -Trend[n] (from step 5);

 

I hope this description helps, Dwayne!

DW

 

 

 

pipaso
Fluorite | Level 6
Could you please write down the steps for backcasting with Holt-Winters Additive model? I could not figure out how to update seasonal index values.
Dwayne
Fluorite | Level 6
To create the initial seasonal index values:

1.      Run a simple regression model with (k-1) dummyvariables. For example, if you need to create quarterly index values, you wouldhave three dummy variables. The resulting model will generate S1, S2, S3parameters that represent the initial unadjusted seasonal values. (unadjusted).

2.      To “create” the value for the kth index (i.e.,the forth season)

a.      average S1, S2, S3 to create S/mean)

b.      the final S4* (adjusted) is = 0 – S/mean)

3.      The unadjusted seasonal values from step 1 nowneed to be adjusted: SK *= Sk + S/mean

4.      If you want to create a “double check” the interceptvalue will also need to be adjusted: B0 + S/mean. The OLS forecastwith the raw unadjusted parameters (S1, S2, S3 and B0) should matchthat created by using the adjusted parameters (S1*, S2*, S3*, S4* and B*0).I always do this as a double check. NOTE: The adjusted values should equalthose indicated by PROC ESM under the “Smoothed States”: Backcast.
Note: the following example has a trend component in addition to seasonality.
Step 1: B0 = 85.36250

                B1= 1.78875    (trend component)

                S1= .44125       (unadjusted season-1)

                S2= -15.89750 (unadjusted season-2)

                S3= -42.41125 (unadjusted season-3)

Step 2: S*4 = 0 – average (.44125,-15.89750,-42.41125)= 0 – (-14.4669) = 14.4669 (adjusted season-4)


Step 3: S*1 = .44125 + 14.4669 = 14.90815          (adjusted season-1)


             S*2= -15.89750 + 14.4669 = -1.4306        (adjusted season-2)

             S*3= -42.41125 + 14.4669 = -27.94435  (adjusted season-3)

             B*0= 85.36250 – 14.4669 = 70.8956)      (adjustedintercept is needed only if you want to double check in EXCEL).


             B*1= B1 * (-1) Required only if your time series has trend and you are usingEXCEL to double check the backcasting and you will need to reverse this (* +1)before proceeding with the forward casting.


Note: the sum of the adjusted seasonal index valuesshould be zero!

pipaso
Fluorite | Level 6

Thank you for the quick response. I tried what you said, but  the sum of the adjusted seasonal index values is not zero. Here is my time series:

 

zts1s2s3
177541100
182202010
182233001
180474000
190305100
191226010
189217001
190238000
191479100
1939710010
1940511001
1960512000
2018113100
2006714010
2070815001
2047616000
2024717100
2035118010
2139319001
2159020000
2123621100

 

The regression results are:

 

 Coeffients
b017669,01053
b1173,2657895
s124,23245614
s229,73157895
s3155,0657895

 

Adjusted seasonal index values:

unadjustedadjusted 
24,2324561493,90906433s1
29,7315789599,40818713s2
155,0657895224,7423977s3
 -69,67660819s4
mean  
69,67660819  

 

Am I doing something wrong?

Dwayne
Fluorite | Level 6
Sorry about that. While the final values from my examplewere correct, the formulas could have been better spelled out.

2.      To “create” the value for the kth index (i.e.,the forth season)

a.      Sum(average S1, S2, S3)/k to create S/mean

b.      the final S4* (adjusted) is = 0 – S/mean)

3.      The unadjusted seasonal values from step1 now need to be adjusted: SK *= Sk - S/mean

In re-creating your time series, I calculated the followingresults:

Step 1: B0 = 17669.01

                B1= 173.2658    (trend component)

                S1= 24.23246    (unadjusted season-1)

                S2= 29.73158    (unadjusted season-2)

                S3= 155.06579  (unadjusted season-3)

 

Step 2:  S/mean = (sum24.23246, 29.73158, 155.06579/4 = 52.2575

               S*4= 0 – (52.2575) = -52.2575 (adjusted season-4)

 

Step 3: S*1 = 24.23246 – ( 52.2575) = -28.0250     (adjusted season-1)

             S*2= 29.73158 – ( 52.2575) = -22.5259      (adjusted season-2)

             S*3= 155.06579 – ( 52.2575) = -102.8083 (adjusted season-3)

 

             B*0= 17669.01 +(  52.2575) = 17721.268    (adjusted intercept is needed only if youwant to double check in EXCEL).

 

Verify: sum (-28.0250,-22.5259, 102.8083,-52.2575) = 0

Whether you use the regression model’s coefficients or theadjusted seasonal index values, your predicted y’s (obs:1-4) should be 17866.51,18045.27, 18343.87, 18362.07

Again, I probably copied the “+/-“ sign and the “/4”incorrectly. Sorry about that. Let me know if this answered your question.

pipaso
Fluorite | Level 6

Thanks again. Now I have my backcasting results (attached as an excel file) and need the initial values for Level, Trend, and Seasonal Index Values in the forecasting step. I know that I will use the original order of my time series. What should the initial values be regarding to the backcasting results?

Dwayne
Fluorite | Level 6
Sorry for the delayed response, but I wanted to plug yourtime series into both SAS’s PROC ESM and my EXCEL spreadsheet to confirm.

Backcasting “STATE=BACKCAST”

Seasonal values are (Note that these values MUST added upto zero):  

S*1 =  -28.0250      (adjustedseason-1)

S*2 =  -22.5259     (adjusted season-2)

S*3 =  -102.8083    (adjusted season-3)

S*4 = -52.2575       (adjusted season-4)

 

Trend: Since you are (in effect) forecasting from period21 to period 1, the trend (B1) calculated from the regression model MUSTbe multiplied by -1 (i.e., it is now -173.2658).

 

Constant: This is simply the actual value for period 21(i.e., 21,236).

 

Weights

SAS calculates the following:

Level Weight = .07211

Trend Weight = .001

Seasonal Weight = .001

 

If you use EXCEL’s “SOLVER” utility you may get a slightlydifferent set of values.

 

Post Backcasting  (“STATE=STARTING”)

Seasonal Values:

After the backcasting is completed, the seasonal values willno longer sum to ZERO. Before they can be used in the “forward casting”, youwill need to adjust them (yet again).

>From My EXECL calculations:

S1 = -27.13818

S2 = -21.86446

S3 = 103.519

S4 = -51.49149

 

This adds up to 3.024881. This MUST be ZERO’d out beforeyou can proceed. To do this:

 

S*1 = -27.13818 – (3.024881/4) = -27.8944

S*2 = -21.86446 – (3.024881/4) = -22.62068

S*3 = 103.519 – (3.024881/4) = 102.76278

S*4 = -51.49149 – (3.024881/4) = -52.2477

 

Trend: Since you are now projecting “forwards” the trendcalculated by the backcasting MUST be multiplied by -1 (i.e., -173.031 * -1 =173.031)

 

Constant: The final constant calculated by thebackcasting must be adjusted in the same manner as the seasonal values (exceptthat we now ADD 3.024881/4:

Constant * = 17662.410 + (3.024881/4) = 17,663.16622

“STATE=FINAL”

In EXCEL you should wind up with the following constant termand set of seasonal values:

Constant = 21,347.760

Trend = 173.081105

S1 = -27.70850

S2 = -22.45757

S3 = 102.91754

S4 = -52.10312

 

Lead=4:

Y22 = 21,347.760 + 173.081105(1) + (-22.45757)= 21,498.38354

Y23 = 21,347.760 + 173.081105(2) + (102.91754)=  21,796.83975

Y24 = 21,347.760 + 173.081105(3) + (-52.10312)=  21,814.9002

Y25 = 21,347.760 + 173.081105(4) + (-27.70850)=  22,012.3738

 

SAS CODE

  *************************

   * AdditiveHolt-Winters *

  *************************;

proc esm data=a print=(estimates forecasts performancestatistics states) printdetails

          seasonality=4 lead=4

          out=out_a outest=outest_a outfor=outfor_a outstat=outstat_a;

 id periodinterval=qtr;

 forecast sales /model=addwinters;

title3 'ESM Procedure';

run;

 

Hope this helps.



pipaso
Fluorite | Level 6

Thanks again, but why is that your backcasting results are different than mine? Were there any mistakes in my excel file? You say the following, but how did you get those values?

 

From My EXECL calculations:
S1 = -27.13818
S2 = -21.86446
S3 = 103.519
S4 = -51.49149

 

Even if I use the weights you mention, I cannot get those results. My trend value after backcasting is also different than yours (Mine is 173.248441693523, yours is 173.081). Am I missing some point? Could you explain it by looking at backcasting results?

 

 

Dwayne
Fluorite | Level 6

Question: Did you create a SAS program / PROC ESM to double check your calculations? If not, I highly recommend that you do so. While SAS doesn’t provide a detailed running calculation summary for it’s backcasting, it does do so for the “foreward casting” portion of the analysis. You can use that to double check that your EXCEL formulas are correct, since the only difference is that the trend must be multiplied by -1 and – instead – of calculating things for observations 21 to 1, calculations are given for observations 1 to 21.

 

I have attached the SAS output. 

 

BACKCASTING (Partial EXCEL)

 

       
(constant)
ϒ
(trend)
 ꝺ (seasonal) ❺-❶
       .072110.001000 .001000  
             
YearTime
Period
Time
Index
Actual
#Disks
Sold
(y)
Projected
#Disks
Sold
(ŷ)
et Model
Constant
(at T)
Trend
(at T)
Seasonal
Time
Index
Seasonal
Index
(Additive)
Model
Constant
- Trend
(at T+1)
Projected
Sales
(ŷ)T+1
         1-28.025000  
         4-52.257456  
         3102.808333  
       21236.000-173.265792-22.52587721062.73421034.709
2021I212123621034.709201.29079 21077.249-173.2511-27.8382220903.99820851.741
2020IV202159020851.741738.25944 20957.234-173.1984-51.5724320784.03620886.844
2020III192139320886.844506.15580 20820.535-173.1623103.2779920647.37320624.847
2020II182035120624.847-273.84734 20627.626-173.1812-22.7799820454.44520426.607

......

2016IV41804718312.625-265.62512 18344.716-173.0414-51.4914918171.67518275.243
2016III31822318275.243-52.24284 18167.908-173.0443103.5190017994.86417972.770
2016II21822017972.770247.23005 18012.692-173.0262-21.8644617839.66517812.581
2016I11775417812.581-58.58127 17835.441-173.0311-27.1381817662.41017610.919
          Re-Normalization3.024881

 

FORECASTING (PARTIAL EXCEL) 

(note the sign reversal in the trend and the required adjustment in the seasonal values)

YearTime
Period
Time
Index
Actual
Hits
(y)
Projected
Hits
(ŷ)
et Model
Constant
(at T)
Trend
(at T)
Seasonal
Time
Index
Seasonal
Index
(Additive)
Model
Constant +
Trend
(at T+1)
Projected
Hits
(ŷ)T+1
    -27.8944    1-27.894400  
    -22.62068    2-22.620700  
    102.76278    3102.762800  
    -52.24771  17663.159173.03074-52.24770017836.19017808.296
2016I11775417808.296-54.296 17832.275173.02681-27.9447818005.30117982.681
2016II21822017982.681237.319 18022.415173.04392-22.4004918195.45818298.221
2016III31822318298.221-75.221 18190.034173.03853102.6930018363.07318310.825
2016IV41804718310.825-263.825 18344.048173.01954-52.4925018517.06818489.123
 

........

2020II182035120783.704-432.704 20774.558173.02712-22.4575720947.58521050.184
2020III192139321050.184342.816 20972.305173.05183102.9175421145.35721092.792
2020IV202159021092.792497.208 21181.210173.08764-52.1031221354.29821326.674
2021I212123621326.674-90.674 21347.760173.08111-27.7085021520.84121498.383

 

 

 

pipaso
Fluorite | Level 6

After your detailed message, I noticed that I made 2 big mistakes. They can be seen from the excel file I uploaded in my previous message. 

1) The order of the seasonal index values was wrong.

2) The formula for Model Constant was wrong.

 

Now, I have the same results with you. Thanks a lot. 

 

Could you please suggest me a source about this subject? Do you figure out the formulas just by looking at the SAS results? Do you follow a source to solve the problem?

 

Thanks again. I am sorry that I have taken lots of your time.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 10 replies
  • 3773 views
  • 3 likes
  • 3 in conversation