Forecasting of Transactional Data
/*--------------------------------------------------------------
SAS Sample Library
Name: esmex02.sas
Description: Example program from SAS/ETS User's Guide,
The ESM Procedure
Title: Forecasting of Transactional Data
Product: SAS/ETS Software
Keys: Exponential Smoothing Models
PROC: ESM
Notes:
--------------------------------------------------------------*/
title;
data websites(label="Transactional Internet data");
/*- time variable definition -*/
keep time;
format time datetime.;
label time="Time of Webhit";
starttime = '12mar2000:00:00:00'dt; /*- Sunday -*/
seedtime = 1234321;
/*- cars variable definition -*/
keep cars;
format cars best12.;
label cars="Number of Car Webhits";
seedcar = 1234321;
/*- boats variable definition -*/
keep boats;
format boats best12.;
label boats="Number of Boat Webhits";
seedboat = 1234321;
/*- planes variable definition -*/
keep planes;
format planes best12.;
label planes="Number of Planes Webhits";
seedplane = 1234321;
/*- engines variable definition -*/
keep engines;
format engines best12.;
label engines="Number of Engine Webhits";
seedengine = 1234321;
/*- simulate the data -*/
do day = 1 to 30;
season = abs(4 - mod(day,7));
nhits = ceil(10*ranuni(seedtime));
intv = 24*3600*ranuni(seedtime)/nhits;
do hits = 1 to nhits;
/*- randomly generate the next time -*/
intv = intv + 24*3600*ranuni(seedtime)/nhits;
intv = int(intv);
time = intnx( 'DTDAY', starttime, day );
time = intnx( 'DTSECOND', time, intv );
/*- randomly generate car data -*/
cars = 1000 + 600*day + 1000*season
+ 10*rannor(seedcar);
cars = int(cars);
/*- randomly generate boats data -*/
boats = 1000 + 1000*season +
+ 10*rannor(seedboat);
boats = int(boats);
/*- randomly generate planes data -*/
planes = 1000 - 10*day +
+ 10*rannor(seedplane);
planes = int(planes);
/*- randomly generate engines data -*/
engines = 1000 + 1*cars - 2*boats + 4*planes
+ 10*rannor(seedengine);
engines = int(engines);
output;
end;
end;
run;
proc esm data=websites out=nextweek lead=7;
id time interval=dtday accumulate=total;
forecast boats cars planes;
run;
title1 "Website Data";
proc sgplot data=nextweek;
series x=time y=boats / markers
markerattrs=(symbol=circlefilled color=red)
lineattrs=(color=red);
series x=time y=cars / markers
markerattrs=(symbol=asterisk color=blue)
lineattrs=(color=blue);
series x=time y=planes / markers
markerattrs=(symbol=circle color=styg)
lineattrs=(color=styg);
refline '11APR2000:00:00:00'dt / axis=x;
xaxis values=('13MAR2000:00:00:00'dt to '18APR2000:00:00:00'dt by dtweek);
yaxis label='Websites' minor;
run;