Good morning,
I have a time process based on 14 hours and I am trying to forecast for each store
the sales based on historical hourly data.
DATA Production;
Store="A"; hour =1 ; sales =9127513; output;
Store="A"; hour =2 ; sales =7632319; output;
Store="A"; hour =3 ; sales =5272615; output;
Store="A"; hour =4 ; sales =7632319; output;
Store="A"; hour =5 ; sales =13160441; output;
Store="A"; hour =6 ; sales =4332659; output;
Store="A"; hour =7 ; sales =6687890; output;
Store="A"; hour =8 ; sales =21424791; output;
Store="A"; hour =9 ; sales =9810671; output;
Store="A"; hour =10 ; sales =5272615; output;
Store="A"; hour =11 ; sales =21989117; output;
Store="A"; hour =12 ; sales =59998842; output;
Store="A"; hour =13 ; sales =527261542; output;
Store="A"; hour =14 ; sales =599986000; output;run;
and so on for 17 stores.
The following process does not work and I get the following error :
%let currenthour=6;
%let lead = %eval(14 - &Currenthour)
proc forecast data =production lead = &lead outactual outlimits
out = AFORECASTOUTPUT outfull outest = AFORECASTOUTPUT2 interval =hour
method=STEPAR trend = 2 alpha=0.05;
by store;
id hour;
var sales; run;
ERROR: Duplicate time interval found at observation number 2 according to the INTERVAL=HOUR
option and the ID variable values. The current ID is date=2 and the previous is date=1,
which are within the same HOUR interval.
interval=hour refers to SAS time intervals, not the name of your variable. Just remove that option and the procedure should use your ID statement variable (hour) as a time value with a default increment of one.
If I do that, I get the following error :
ERROR: Observation number 14 is out of order according to the ID variable values. The current ID
is hour=1, the previous ID was hour=13.
You need
BY STORE DAY;
Hello -
It may be worthwhile to run PROC ESM instead on PROC FORECAST.
Here is an example which should work for your data (even when adding several stores):
proc esm data=production plot=forecasts lead=&lead outfor=work.AFORECASTOUTPUT;
forecast sales/model=damptrend;
by store;
run;
Of course ESM will assume the same model for all stores (in my code I used a damped trend exponential smoothing model, which seems to be appropriate for your example), but at least the parameters for each store will be different.
Thanks,
Udo
the variable HOUR is just a doule, not a datetime variable, You can either change the format of HOUR to datetime or trick the proc with the option interval = day
proc forecast data =production lead = 12 outactual outlimits
out = AFORECASTOUTPUT outfull outest = AFORECASTOUTPUT2 interval =hour
method=STEPAR trend = 2 alpha=0.05 interval = day;
by store;
id hour;
var sales;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.