Source Code to Display a Data Set in Table or Graph Format From The Forecast Command Builder
/* Copyright(c) 1998 by SAS Institute Inc., Cary, NC USA */
/* FORCCOUT.SCL, used with the Forecast Command */
/* Builder, FORCCMD.SCL. */
/* Display forecast data set as either a table or */
/* a graph. This version uses a graph object */
/* to display the graph. The list of output */
/* data sets is taken from the command list. */
/* Ordinarily each data set will have the same */
/* name as the input series, making it easy to */
/* identify the series associated with the output. */
length dsn $ 41 text $ 8 outname $ 41 timeid $ 32 cmd $ 200;
rc = rc;
entry cmdlist 8;
init:
outlist = makelist(); * List of output data set names;
idlist = makelist(); * List of ID variable names;
do i=1 to listlen( cmdlist );
cmd = getitemc( cmdlist, i );
/* Get the output data set name from the command. */
call method( 'forcmtd.scl', 'getarg', cmd,
'OUT=', 41, outname );
if outname ^= ' '
then outlist = insertc( outlist, outname, -1 );
/* Get the time id variable name from the command. */
call method( 'forcmtd.scl', 'getarg', cmd,
'ID=', 32, timeid );
if timeid = ' ' then timeid = 'DATE';
idlist = insertc( idlist, timeid, -1 );
end;
outplist:
call notify( 'outplist', '_get_last_sel_',
row, issel, text );
if issel then do;
dsn = getitemc( outlist, row );
if ^exist( dsn ) then do;
_msg_ = dsn || ' does not exist.';
return;
end;
/* Display graph of forecast data set. */
if viewtype = 1 then do;
timeid = getitemc( idlist, row );
link grafdata;
call display( 'forccgrf.frame', dsn, timeid, forcstrt );
end;
/* Display table view of forecast data set. */
else call execcmdi( 'viewtable ' || dsn );
end;
if row then
call notify( 'outplist', '_select_row_',
row, 'OFF' );
return;
term:
outlist = dellist( outlist );
idlist = dellist( idlist );
rc = delete( 'work.tempf' );
return;
/* Prepare a temporary dataset to enable overlay graphing. */
grafdata:
/* Find forcstrt, the time ID value at which */
/* the forecast time range begins. */
dsid = open( dsn, 'IN' );
rc = where( dsid, 'ACTUAL ^= .' );
rc = varstat( dsid, timeid, 'max', maxtid );
rc = where( dsid );
tidvnum = varnum( dsid, timeid );
rc = locaten( dsid, tidvnum, maxtid, 'a' );
obs = curobs( dsid ) + 1;
rc = fetchobs( dsid, obs );
forcstrt = getvarn( dsid, tidvnum );
rc = close( dsid );
submit continue;
data tempf;
set &dsn;
keep &dsn Legend &timeid;
if &timeid < &forcstrt then do;
&dsn = actual;
Legend = 'Actual Values ';
output;
&dsn = predict;
Legend = 'Model Predictions';
output;
end;
else do;
&dsn = predict;
Legend = 'Forecast';
output;
&dsn = upper;
Legend = 'Upper C.L.';
output;
&dsn = lower;
Legend = 'Lower C.L.';
output;
end;
run;
endsubmit;
return;
quit:
call execcmd( 'end' );
return;
5555
Statistics and Operations Research Home Page | Time Series Forecasting System