BookmarkSubscribeRSS Feed
nketata
Obsidian | Level 7

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.

5 REPLIES 5
PGStats
Opal | Level 21

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. 

PG
nketata
Obsidian | Level 7

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.

 

PGStats
Opal | Level 21

You need

 

BY STORE DAY;

PG
udo_sas
SAS Employee

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

 

alexchien
Pyrite | Level 9

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 5 replies
  • 1602 views
  • 0 likes
  • 4 in conversation