I'm running Viya 3.5
My code gnerates a model and I can derive a score using proc astore immediately after the training has finished.
But when I close the session and come back I cannot recover the model.
/* filename score temp; */
cas mySession sessopts=(caslib="risk");
proc cas;
trnTable = {name="FOPERENT_DEC22_ETL_F",
where="_partind_=1 and strip(orig)='data'
and (^missing(FEC_CANCELACIONXFINIQUITO) or 1=1)
and missing_called ne . and flag_poor_data",
computedvars={{name="_year"}, {name="_tma"}, {name="contract_yearly_kms"}, {name="opc"}, {name="maturity"} }
computedvarsprogram="_year=put(year(F_INICIO_SERVICIOS), 4.); _tma=substr(tmaimg,1,3); maturity=out_months_passed/out_APZMTO;
contract_yearly_kms=out_KM_CONTRATADO/out_APZMTO*12; opc=imp_to-val_ba;"};
vldTable = {name="FOPERENT_DEC22_ETL_F",
where="_partind_=0 and strip(orig)='data'
and ^missing(FEC_CANCELACIONXFINIQUITO)
and missing_called ne . and flag_poor_data",
computedvars={{name="_year"}, {name="_tma"}, {name="contract_yearly_kms"}, {name="opc"}, {name="maturity"}}
computedvarsprogram="_year=put(year(F_INICIO_SERVICIOS), 4.); _tma=substr(tmaimg,1,3); maturity=out_months_passed/out_APZMTO;
contract_yearly_kms=out_KM_CONTRATADO/out_APZMTO*12; opc=imp_to-val_ba;" };
decisionTree.gbtreeTrain result=r /
table=trnTable
inputs={"from_brand", "from_gama_agg", "_year", "combustible", "contract_yearly_kms", "_tma", 'No_NM_TTAL_OP',
'SubAdministrativeArea', 'color', 'opc', 'maturity' }
target="out_yearly_kms"
saveState = {name='gb_yearly_kms_v3', caslib='onair', promote=true}
maxlevel =16
maxbranch=2
LEAFSIZE=5
nbins =20
binorder =1
missing= "USEINSEARCH"
varImp =true
code={labelid=999, comment=true, tabForm=true}
casOut={
name='hmeq_dtree_trn_v3',
replace=true
};
run;
print r['ModelInfo'];
print r['DTreeVarImpInfo'];
run;
/* saveresult r['CodeGen'] file=score; */
run;
The scoring works like this:
proc astore;
describe rstore=onair.GB_YEARLY_KMS_V3;
quit;
data RISK.FOPERENT_DEC22_ETL_F1;
set RISK.FOPERENT_DEC22_ETL_F;
_year=put(year(F_INICIO_SERVICIOS), 4.); _tma=substr(tmaimg,1,3); maturity=out_months_passed/out_APZMTO;
contract_yearly_kms=out_KM_CONTRATADO/out_APZMTO*12; opc=imp_to-val_ba;
run;
proc astore;
score data=RISK.FOPERENT_DEC22_ETL_F1
rstore=ONAIR.GB_YEARLY_KMS_V3
/* epcode="/caslibs/marketing/dmcas_epscorecode.sas" */
out=RISK.FOPERENT_DEC22_ETL_FF12
copyvars=(orig out_yearly_kms FEC_CANCELACIONXFINIQUITO flag_poor_data missing_called _PartInd_ cod_ope ) ;
run;
Then I save successfully to disk using these lines and for the next session I load into memory.
proc cas ;
table.save /
table={name="GB_YEARLY_KMS_V3", caslib="onair"} compress=true replace=true
name="GB_YEARLY_KMS_V3.sashdat" caslib="onair"
exportOptions={
fileType="auto"
};
run;
Now the proc astore throws out the following error:
ERROR: Store GB_YEARLY_KMS_V3 has no observations. ERROR: Action score failed. ERROR: The action stopped due to errors.
Hello,
Can you try :
saveState = {name='gb_yearly_kms_v3', caslib='PUBLIC', promote=true}
?? ( if PUBLIC CASLIB is not disabled at your site )
Table (which is an analytic store for the model as a binary object) should stay there across sessions!
Otherwise you can try :
BR,
Koen
How are you reloading the model when you come back and try to score?
As you have saved the savestate table as a sashdat, you will need to load it back into the new session appropriately. Based upon your example here is something that might be close?
proc cas;
table.loadTable /
path = "GB_YEARLY_KMS_V3.sashdat"
caslib = "onair"
casout = {name="GB_YEARLY_KMS_V3", caslib="onair", replace=true}
;
run;
Then afterwards the astore call should run as it did in the previous session.
Hello,
Can you try :
saveState = {name='gb_yearly_kms_v3', caslib='PUBLIC', promote=true}
?? ( if PUBLIC CASLIB is not disabled at your site )
Table (which is an analytic store for the model as a binary object) should stay there across sessions!
Otherwise you can try :
BR,
Koen
Thank you @sbxkoenk and @RalphAbbey .
It works over sessions with the following code approach.
...
target="out_yearly_kms"
saveState = {name='temp_gb_yearly_kms', caslib='public', promote=true}
...
proc astore;
describe rstore=public.temp_GB_YEARLY_KMS;
download rstore=public.temp_GB_YEARLY_KMS store="/caslibs/busdev/yearly";
quit;
proc astore;
upload rstore=public.temp_GB_YEARLY_KMS
store="/caslibs/busdev/yearly";
quit;
proc astore;
describe rstore=public.temp_GB_YEARLY_KMS epcode="/caslibs/busdev/yearly_epcode.sas";
quit;
proc astore;
score data=RISK.FOPERENT_DEC22_ETL_F1
rstore=public.temp_GB_YEARLY_KMS
out=RISK.FOPERENT_DEC22_ETL_FF12
copyvars=( out_yearly_kms _PartInd_ from_gama_agg ) ;
run;
In addition, I've implemented an override decision placed in the epcode, that's nice.
proc astore;
score data=RISK.FOPERENT_DEC22_ETL_F1
rstore=public.temp_GB_YEARLY_KMS
epcode="/caslibs/busdev/yearly_epcode_v2.sas"
out=RISK.FOPERENT_DEC22_ETL_FF12 ;
run;
Here for example, the business policy could mandate that special car models receive a customized scoring. It's the line after method postScoreRecord();
data sasep.out; dcl package score sc(); dcl nchar(200) "from_brand"; dcl nchar(200) "from_gama_agg"; dcl nchar(4) "_year"; dcl nchar(1) "Combustible"; dcl double "contract_yearly_kms"; dcl double "No_NM_TTAL_OP"; dcl nchar(84) "SubAdministrativeArea" having format $CHAR42.; dcl double "opc"; dcl double "maturity"; dcl double "out_yearly_kms"; dcl double "P_out_yearly_kms" having label n'Predicted: out_yearly_kms'; dcl nchar(4) "_WARN_" having label n'Warnings'; Keep "P_out_yearly_kms" "from_gama_agg" "_WARN_" ; varlist allvars[_all_]; method init(); sc.setvars(allvars); sc.setKey(n'xxxxxxxxxxxxxxxxxxxxxxxx'); end; method preScoreRecord(); end; method postScoreRecord(); if strip(from_gama_agg)='Q5' then P_out_yearly_kms = 77777; end; method term(); end; method run(); set sasep.in; preScoreRecord(); sc.scoreRecord(); postScoreRecord(); end; enddata;
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!
Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.
Find more tutorials on the SAS Users YouTube channel.