The CESM Procedure
Example 8.2 Forecasting of Transactional Data
This example illustrates how you can use the CESM procedure to forecast transactional data.
The statements in this example assume that your CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref.
The following DATA step creates a data table from data that were recorded at several internet websites. The data table mycas.websites contains a variable Time (which represents time) and the variables Engine, Boats, Cars, and Planes, which represent internet website data. Each value of the Time variable is recorded in ascending order, and the values of each of the other variables represent a transactional data series.
data mycas.websites(label="Transactional internet data");
/*- time variable definition -*/
keep time;
format time datetime.;
label time="Time of Web Hit";
starttime = '12mar2000:00:00:00'dt; /*- Sunday -*/
seedtime = 1234321;
/*- cars variable definition -*/
keep cars;
format cars best12.;
label cars="Number of Car Web Hits";
seedcar = 1234321;
/*- boats variable definition -*/
keep boats;
format boats best12.;
label boats="Number of Boat Web Hits";
seedboat = 1234321;
/*- planes variable definition -*/
keep planes;
format planes best12.;
label planes="Number of Planes Web Hits";
seedplane = 1234321;
/*- engines variable definition -*/
keep engines;
format engines best12.;
label engines="Number of Engine Web Hits";
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;
The following CESM procedure statements forecast each of the transactional data series:
proc cesm data=mycas.websites outfor=mycas.nextweek;
id time interval=dtday accumulate=total;
forecast boats cars planes / lead=7 method=simple;
run;
The preceding statements accumulate the data into a daily time series, generate forecasts for the Boats, Cars, and Planes variables in the input data table mycas.websites for the next week, and store the forecasts in the mycas.nextWeek data table, which is specified in the OUTFOR= option.
The following statements plot the forecasts that are related to the internet data:
%plotActualPredict(mycas.nextweek, time, boats, '11APR2000:00:00:00'dt,
'13MAR2000:00:00:00'dt, '18APR2000:00:00:00'dt, dtweek, 'Time of Web Hit',
0, 50000, 10000, 'Web Hits');
%plotActualPredict(mycas.nextweek, time, cars, '11APR2000:00:00:00'dt,
'13MAR2000:00:00:00'dt, '18APR2000:00:00:00'dt, dtweek, 'Time of Web Hit',
0, 250000, 50000, 'Web Hits');
%plotActualPredict(mycas.nextweek, time, planes, '11APR2000:00:00:00'dt,
'13MAR2000:00:00:00'dt, '18APR2000:00:00:00'dt, dtweek, 'Time of Web Hit',
0, 12000, 2000, 'Web Hits');
The plots are shown in Output 8.2.1, Output 8.2.2, and Output 8.2.3. The historical data and their fits are shown to the left of the reference line, and the forecasts for the next seven days are shown to the right.
Output 8.2.1: Internet Data Forecast Plots (Boats)

Output 8.2.2: Internet Data Forecast Plots (Cars)

Output 8.2.3: Internet Data Forecast Plots (Planes)
