Source Code for the Forecast Command Builder
/* Copyright(c) 1998 by SAS Institute Inc., Cary, NC USA */
/* FORCCMD.SCL: Source code for Forecast Command Builder*/
/* demo application. This code can be copied for use as */
/* a demo or an example. To run the application, you do */
/* not need source code. Use the command */
/* AF C=SASHELP.FORCAST.FORCCMD.FRAME in Version 7.01. */
/* To build the application, copy FORCCMD.FRAME from the */
/* forcast catalog provided in the sashelp library with */
/* SAS/ETS software. Copy this source code to an SCL */
/* catalog entry in the same catalog and with the same */
/* name as the frame entry, then open the frame entry */
/* and compile. */
length cmdtext $ 200 btnname $ 8 critname $ 40 widgname $ 8;
length returnString $ 40;
init:
/* Instantiate the SAS Data File Class. */
dfile = instance(loadclass('sashelp.fsp.datafile.class'));
/* Create lists. */
varlist = makelist(); * Variable information list;
serpopup = makelist(); * List of variables for popup;
intervals = makelist(); * List of possible intervals/formats;
entries = makelist(); * List of valid entry types;
entlabels = makelist(); * List of valid entry type labels;
stats = makelist(); * List of statistics of fit;
modcpu = makelist(); * List of fit criteria for popup;
modcnames = makelist(); * List of names corresponding to modcpu;
confpu = makelist(); * Confidence limits popup list;
horzpu = makelist(); * Horizon values popup list;
cmdlist = makelist(); * Command list;
attrlist = makelist(); * Attibute list for savelist function;
/* Populate the intervals list */
rc = fillist( 'catalog', 'sashelp.etstool.interval.slist',
intervals );
intpopup = getniteml( intervals, 'interval_names' );
/* Populate the list of entry names. */
entries = insertc(entries, 'FORECAST', -1 );
entries = insertc(entries, 'AUTOFIT', -1 );
entries = insertc(entries, 'MAIN', -1 );
entries = insertc(entries, 'DEVMOD', -1 );
entries = insertc(entries, 'VIEWMOD', -1 );
entries = insertc(entries, 'VIEWSER', -1 );
entries = insertc(entries, ' ', -1 );
/* Populate the corresponding list of entry labels. */
entlabels = insertc(entlabels, 'FORECAST - Unattended Forecasting', -1 );
entlabels = insertc(entlabels, 'AUTOFIT - Unattended Automatic Model Fitting',-1 );
entlabels = insertc(entlabels, 'MAIN - Time Series Forecasting Window', -1 );
entlabels = insertc(entlabels, 'DEVMOD - Develop Models Window', -1 );
entlabels = insertc(entlabels, 'VIEWMOD - Model Viewer Window', -1 );
entlabels = insertc(entlabels, 'VIEWSER - Series Viewer Window', -1 );
entlabels = insertc(entlabels, 'None (default is MAIN)', -1 );
/* Populate the conf limit list. */
confpu = insertc( confpu, '50' );
confpu = insertc( confpu, '75' );
confpu = insertc( confpu, '90' );
confpu = insertc( confpu, '925');
confpu = insertc( confpu, '95' );
confpu = insertc( confpu, '975');
confpu = insertc( confpu, '99' );
/* Populate the horizon popup list. */
horzpu = insertc( horzpu, '1', -1 );
horzpu = insertc( horzpu, '2', -1 );
horzpu = insertc( horzpu, '3', -1 );
horzpu = insertc( horzpu, '4', -1 );
horzpu = insertc( horzpu, '5', -1 );
horzpu = insertc( horzpu, '6', -1 );
horzpu = insertc( horzpu, '7', -1 );
horzpu = insertc( horzpu, '8', -1 );
horzpu = insertc( horzpu, '9', -1 );
horzpu = insertc( horzpu, '10', -1 );
horzpu = insertc( horzpu, '11', -1 );
horzpu = insertc( horzpu, '12', -1 );
/* Populate the model criterion popup list. */
rc = fillist( 'catalog', 'sashelp.forcast.fitstats.slist',
stats );
snames = getniteml( stats, 'statnames' );
slabels= getniteml( stats, 'statlabels' );
sflags = getniteml( stats, 'statmax' );
do i=1 to listlen( snames );
if getitemn( sflags, i ) >= 0
then do;
modcpu = insertc( modcpu, getitemc( slabels, i ));
modcnames = insertc( modcnames, getitemc( snames, i ));
end;
end;
modcpu = insertc( modcpu,
'None (default is Root Mean Square Error)', -1 );
modcnames = insertc( modcnames, ' ', -1 );
/* Initialize the refitopt radio box. */
refitopt = 'Neither';
/* Initially gray out the delete button on the command list tab. */
call notify( 'delete', '_gray_' );
/* Set defaults. */
entry = 'FORECAST';
/* Initially gray the save button. */
call notify( 'save', '_gray_' );
/* If there is a saved command list, ungray the load button. */
if ^cexist( 'sasuser.fmsproj._cmdlst_.slist' )
then call notify( 'load', '_gray_' );
return; /* init */
main:
/* Control the message display in the msgtext text widget. */
call send( _self_, '_get_current_widget_', widgetid );
call send( widgetid, '_get_name_', widgname );
if widgname ^in ('LOAD', 'SAVE' )
then call notify( 'msgtext', '_set_text_', ' ' );
return;
term:
/* Term the SAS Data File Class instance. */
call send( dfile, '_term_' );
/* Delete lists. */
varlist = dellist(varlist);
serpopup = dellist(serpopup);
intervals = dellist(intervals);
entries = dellist(entries);
entlabels = dellist(entlabels);
stats = dellist(stats);
modcpu = dellist(modcpu);
modcnames = dellist(modcnames);
confpu = dellist(confpu);
horzpu = dellist(horzpu);
cmdlist = dellist(cmdlist);
attrlist = dellist(attrlist);
return; /* term */
buildcmd:
/* Build the current command using all info currently entered. */
cmdtext = 'FORECAST';
if seldsn ^= _blank_
then cmdtext = cmdtext || ' DATA=' || seldsn;
if selser ^= _blank_
then cmdtext = cmdtext || ' VAR=' || selser;
if seltid ^= _blank_
then cmdtext = cmdtext || ' ID=' || seltid;
if selint ^= _blank_
then cmdtext = cmdtext || ' INTERVAL=' || selint;
if selproj ^= _blank_
then cmdtext = cmdtext || ' PROJECT=' || selproj;
if entry ^= _blank_
then cmdtext = cmdtext || ' ENTRY=' || entry;
if outdsn ^= _blank_
then cmdtext = cmdtext || ' OUT=' || outdsn;
if conflim ^= _blank_
then cmdtext = cmdtext || ' CLIMIT=' || conflim;
if horizon ^= _blank_
then cmdtext = cmdtext || ' HORIZON=' || horizon;
if critname ^= _blank_
then cmdtext = cmdtext || ' STAT=' || critname;
if upcase(refitopt) ^= 'NEITHER'
then cmdtext = cmdtext || ' ' || refitopt;
call notify( 'curcmd1', '_clear_' );
call notify( 'curcmd2', '_clear_' );
call notify( 'curcmd1', '_set_text_', cmdtext );
call notify( 'curcmd2', '_set_text_', cmdtext );
return; /* buildcmd */
clear:
/* Clear the command list. */
rc = clearlist( cmdlist );
call notify( 'cmdlb', '_update_' );
call notify( 'save', '_gray_' );
return;
clearflds:
/* Clear some fields when data set changes. */
selser = '';
seltid = '';
selint = '';
outdsn = '';
selproj = '';
return;
cmdlb:
/* Command list box. */
call notify( 'cmdlb', '_get_last_sel_',
row, issel );
if row
then do;
call notify( 'delete', '_ungray_' );
/* Parse the command in the selected row and use it */
/* to populate the widgets so user can edit a */
/* previously saved command. */
cmdtext = getitemc( cmdlist, row );
call notify( 'curcmd1', '_clear_' );
call notify( 'curcmd2', '_clear_' );
call notify( 'curcmd1', '_set_text_', cmdtext );
call notify( 'curcmd2', '_set_text_', cmdtext );
call method( 'forcmtd.scl', 'getarg', cmdtext,
'DATA=', 40, returnString );
seldsn = returnString;
if seldsn ^= _blank_ then link getvars;
call method( 'forcmtd.scl', 'getarg', cmdtext,
'VAR=', 32, returnString );
selser = returnString;
call method( 'forcmtd.scl', 'getarg', cmdtext,
'ID=', 32, returnString );
seltid = returnString;
call method( 'forcmtd.scl', 'getarg', cmdtext,
'INTERVAL=', 32, returnString );
selint = returnString;
call method( 'forcmtd.scl', 'getarg', cmdtext,
'PROJECT=', 17, returnString );
selproj = returnString;
call method( 'forcmtd.scl', 'getarg', cmdtext,
'ENTRY=', 8, returnString );
entry = returnString;
call method( 'forcmtd.scl', 'getarg', cmdtext,
'HORIZON=', 8, returnString );
horizon = returnString;
call method( 'forcmtd.scl', 'getarg', cmdtext,
'CLIMIT=', 8, returnString );
conflim = returnString;
call method( 'forcmtd.scl', 'getarg', cmdtext,
'STAT=', 40, returnString );
sel = searchc( modcnames, returnString );
if 0 < sel < listlen(modcpu)
then crit = getitemc( modcpu, sel );
else crit = ' ';
call method( 'forcmtd.scl', 'getarg', cmdtext,
'OUT=', 17, returnString );
outdsn = returnString;
if index( cmdtext, 'REFIT' )
then refitopt = 'REFIT' ;
else if index( cmdtext, 'REEVAL' )
then refitopt = 'REEVAL';
else refitopt = 'NEITHER';
end;
else call notify( 'delete', '_ungray_' );
return;
critctrl:
/* Model fit criterion selector. */
sel = popmenu( modcpu );
if ^sel then return;
crit = getitemc( modcpu, sel );
critname = getitemc( modcnames, sel );
if critname = ' ' then crit = ' ';
link buildcmd;
return;
confctrl:
/* Confidence limits selector. */
sel = popmenu( confpu, 20 );
if ^sel then return;
conflim = getitemc( confpu, sel );
link buildcmd;
return;
conflim:
/* Confidence limits input field. */
link buildcmd;
return;
delete:
/* Delete button on command list tab. */
call notify( 'cmdlb', '_get_last_sel_',
row, issel );
if ^row then return;
cmdlist = delitem( cmdlist, row );
call notify( 'cmdlb', '_update_' );
if listlen( cmdlist ) < 1
then do;
call notify( 'save', '_gray_' );
call notify( 'delete', '_gray_' );
end;
else if listlen( cmdlist ) >= row
then call notify( 'cmdlb', '_select_row_', row );
else call notify( 'cmdlb', '_select_row_', 1 );
link clearflds;
seldsn = '';
horizon = '';
conflim = '';
crit = '';
refitopt = 'Neither';
call notify( 'curcmd1', '_clear_' );
call notify( 'curcmd2', '_clear_' );
cursor seldsn;
return;
dsctrl:
/* Input data selector: Prompt for a SAS data set or view. */
seldsn = dirlist( '*', 'DATA', 1, 'Y' );
link seldsn;
return;
entrctrl:
/* Entry selector. Display labels but return name */
/* corresponding to selected label. */
sel = popmenu( entlabels, 20 );
if ^sel then return;
entry = getitemc( entries, sel );
if entry ^= 'FORECAST' then outdsn = ' ';
link buildcmd;
return;
getvars:
/* Get list of variables in selected data set. */
call send( dfile, '_setup_', seldsn );
call send( dfile, '_get_members_', varlist, '', 'name' );
if listlen( varlist ) < 1 then return;
/* Convert to a simple list of var names for popmenu function. */
rc = clearlist( serpopup );
do i=1 to listlen( varlist );
serpopup = insertc( serpopup, nameitem(varlist,i), -1 );
end;
return;
horzctrl:
/* Forecast horizon selector. */
sel = popmenu( horzpu, 20 );
if ^sel then return;
horizon = getitemc( horzpu, sel );
link buildcmd;
return;
horizon:
/* Forecast horizon input field. */
link buildcmd;
return;
intctrl:
/* Interval selector. */
sel = popmenu( intpopup, 20 );
if ^sel then return;
selint = getitemc( intpopup, sel );
link buildcmd;
return;
load:
/* Retrieve the saved command list, if it exists. */
rc = fillist( 'catalog', 'sasuser.fmsproj._cmdlst_.slist',
cmdlist );
if rc then return;
call notify( 'msgtext', '_set_text_',
'Command list was loaded from sasuser.fmsproj._cmdlst_.slist');
call notify( 'cmdlb', '_update_' );
call notify( 'save', '_ungray_' );
return;
outctrl:
/* Output data set selector. */
/* Prompt for a SAS data set to save forecasts to. */
outdsn = dirlist( '*', 'DATA', 1, 'Y' );
link buildcmd;
return;
outdsn:
/* Output data set input field. */
link buildcmd;
return;
projctrl:
/* Project selector. */
selproj = catlist( 'sasuser.fmsproj', 'FMSPROJ', 1, 'Y' );
link buildcmd;
return;
refitopt:
link buildcmd;
return;
save:
/* Save button on command list tab. */
/* Save the command list to a fixed location. */
rc = savelist( 'catalog', 'sasuser.fmsproj._cmdlst_.slist',
cmdlist, attrlist,
'Command list saved by forcdemo.frame.' );
if rc then return;
call notify( 'msgtext', '_set_text_',
'Command list was saved to sasuser.fmsproj._cmdlst_.slist');
call notify( 'load', '_ungray_' );
return;
seldsn:
/* Input data set input field. */
if seldsn = _blank_ then return;
link clearflds;
link buildcmd;
link getvars;
return;
selser:
/* Series input field. */
if selser = _blank_ then return;
/* Set project and outdsn to same name as series by default. */
selproj = selser;
outdsn = selser;
link buildcmd;
return;
serctrl:
/* Series selector. */
sel = popmenu( serpopup, 20 );
if ^sel then return;
selser = getitemc( serpopup, sel );
link selser;
return;
selint:
/* Interval input field. */
link buildcmd;
return;
selproj:
/* Project input field. */
link buildcmd;
return;
seltid:
/* Time ID input field. */
link buildcmd;
return;
tidctrl:
/* Time ID selector. */
sel = popmenu( serpopup, 20 );
if ^sel then return;
seltid = getitemc( serpopup, sel );
link buildcmd;
return;
toolbar:
/* Perform action assigned to toolbar button selected. */
call notify( 'toolbar', '_get_last_sel_', sel, issel, btnname );
select( btnname );
when( 'ADD' )
cmdlist = insertc( cmdlist, cmdtext, -1 );
call notify( 'cmdlb', '_update_' );
call notify( 'save', '_ungray_' );
when( 'RUNCUR' )
call execcmdi( cmdtext );
if entry='FORECAST' then do;
templist = makelist();
templist = insertc( templist, cmdtext, -1 );
call display( 'forccout.frame', templist );
templist = dellist( templist );
end;
*call execcmd( 'END' );
when( 'RUNLIST' )
do i = 1 to listlen( cmdlist );
cmdtext = getitemc( cmdlist, i );
call execcmdi( cmdtext );
end;
if entry='FORECAST'
then call display( 'forccout.frame', cmdlist );
call execcmd( 'END' );
when( 'QUIT' ) call execcmd( 'END' );
otherwise;
end;
return;
/* Nonexecutable: Prevent compiler warnings. */
rc = rc;
Statistics and Operations Research Home Page | Time Series Forecasting System