Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.
Source: SAS Viya documentation https://go.documentation.sas.com/doc/en/pgmsascdc/default/casecon/casecon_tsm_sect127.htm
/*******************************************/
/* */
/* RNNSPEC with DIAGNOSE object specs */
/* based on example from Taiyeong Lee */
/* modified 20230622 by Beth Ebersole */
/* */
/*******************************************/
/* Create a CAS session and a CAS library */
cas mySession sessopts=(caslib=casuser timeout=1800 locale="en_US");
libname mycas cas sessref = mySession;
data mycas.air;
set sashelp.air;
run;
proc tsmodel data=mycas.air outlog=mycas.outlog
logcontrol=(error=keep warning=keep note=keep none=keep)
outobj=(outstat=mycas.outstat modInfo=mycas.modInfo
airSelect=mycas.airSelect);
id date interval=month;
var air;
require atsm tsm;
SUBMIT;
declare object dataFrame(tsdf);
rc = dataFrame.Initialize();
rc = dataFrame.AddY(air);
rc = dataFrame.SetOption('seasonality', 12);
declare object diagSpec(diagspec);
rc = diagSpec.Open();
rc = diagSpec.SetARIMAX();
rc = diagSpec.SetUCM();
rc = diagSpec.Close();
declare object diagnose(diagnose);
rc = diagnose.Initialize(dataFrame);
rc = diagnose.SetSpec(diagSpec);
rc = diagnose.SetOption('holdout', 12);
rc = diagnose.Run();
declare object rnnspec_GRU(rnnspec);
rc = rnnspec_GRU.Open( );
rc = rnnspec_GRU.SetOption(
'RNNTYPE','GRU',
'NINPUT', 12,
'NVALIDATION',12,
'NLAYER', 4,
'NNEURONH',30,
'NORMALIZE', 'STD',
'BATCHSELECTION', 'SEQ',
'POSTTRAIN', 'YES',
'SEED', 12345
);
rc = rnnspec_GRU.SetOptimizer(
'ALGORITHM','ADAM',
'LEARNINGRATE', 0.1,
'BETA1', 0.8,
'BETA2', 0.9,
'LEARNINGPOLICY', 'STEP',
'STEPSIZE', 5,
'GAMMA', 0.5,
'STAGNATION', 20,
'MINIBATCHSIZE', 8,
'WARMUPEPOCHS',15,
'MAXEPOCHS', 100
);
rc = rnnspec_GRU.Close();
declare object rnnspec_LSTM(rnnspec);
rc = rnnspec_LSTM.Open( );
rc = rnnspec_LSTM.SetOption(
'RNNTYPE','LSTM',
'NINPUT', 12,
'NVALIDATION', 0,
'NLAYER', 4,
'NNEURONH',30,
'NORMALIZE', 'STD',
'BATCHSELECTION','SEQ',
'POSTTRAIN', 'NO',
'SEED', 12345
);
rc = rnnspec_LSTM.SetOptimizer(
'ALGORITHM','ADAM',
'LEARNINGRATE', 0.01,
'BETA1', 0.8,
'BETA2', 0.9,
'LEARNINGPOLICY', 'STEP',
'STEPSIZE', 5,
'GAMMA', 0.5,
'STAGNATION', 20,
'MINIBATCHSIZE',8,
'WARMUPEPOCHS',15,
'MAXEPOCHS', 100
);
rc = rnnspec_LSTM.close();
declare object foreng(foreng);
rc = foreng.Initialize(diagnose);
rc = foreng.addFrom(rnnspec_GRU);
rc = foreng.addFrom(rnnspec_LSTM);
rc = foreng.SetOption('lead', 12);
rc = foreng.SetOption('alpha',0.05);
rc = foreng.setOption('SEASONTEST','NONE');
rc = foreng.Run();
declare object modInfo(outmodelinfo);
rc = modInfo.Collect(foreng);
declare object airSelect(outselect);
rc = airSelect.Collect(foreng);
declare object outstat(outstat);
rc = outstat.Collect(foreng);
ENDSUBMIT;
print outlog;
quit;
proc print data=mycas.modInfo;
run;
proc print data=mycas.airSelect;
run;
proc print data=mycas.outstat;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.