<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic savestate issue with decisiontree train action cas in SAS Data Science</title>
    <link>https://communities.sas.com/t5/SAS-Data-Science/savestate-issue-with-decisiontree-train-action-cas/m-p/857362#M10428</link>
    <description>&lt;P&gt;I'm running Viya 3.5&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My code gnerates a&amp;nbsp; model and I can derive a score using proc astore immediately after the training has finished.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But when I close the session and come back I cannot recover the model.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/* 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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The scoring works like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then I save successfully to disk using these lines and for the next session I load into memory.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now the proc astore throws out the following error:&lt;/P&gt;
&lt;PRE&gt;ERROR: Store GB_YEARLY_KMS_V3 has no observations.
ERROR: Action score failed.
ERROR: The action stopped due to errors.&lt;/PRE&gt;</description>
    <pubDate>Mon, 06 Feb 2023 14:08:54 GMT</pubDate>
    <dc:creator>acordes</dc:creator>
    <dc:date>2023-02-06T14:08:54Z</dc:date>
    <item>
      <title>savestate issue with decisiontree train action cas</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/savestate-issue-with-decisiontree-train-action-cas/m-p/857362#M10428</link>
      <description>&lt;P&gt;I'm running Viya 3.5&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My code gnerates a&amp;nbsp; model and I can derive a score using proc astore immediately after the training has finished.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But when I close the session and come back I cannot recover the model.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/* 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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The scoring works like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then I save successfully to disk using these lines and for the next session I load into memory.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now the proc astore throws out the following error:&lt;/P&gt;
&lt;PRE&gt;ERROR: Store GB_YEARLY_KMS_V3 has no observations.
ERROR: Action score failed.
ERROR: The action stopped due to errors.&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Feb 2023 14:08:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/savestate-issue-with-decisiontree-train-action-cas/m-p/857362#M10428</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2023-02-06T14:08:54Z</dc:date>
    </item>
    <item>
      <title>Re: savestate issue with decisiontree train action cas</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/savestate-issue-with-decisiontree-train-action-cas/m-p/858346#M10429</link>
      <description>&lt;P&gt;How are you reloading the model when you come back and try to score?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc cas;
   table.loadTable /
   path = "GB_YEARLY_KMS_V3.sashdat"
   caslib = "onair"
   casout = {name="GB_YEARLY_KMS_V3", caslib="onair", replace=true}
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then afterwards the astore call should run as it did in the previous session.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 21:13:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/savestate-issue-with-decisiontree-train-action-cas/m-p/858346#M10429</guid>
      <dc:creator>RalphAbbey</dc:creator>
      <dc:date>2023-02-10T21:13:35Z</dc:date>
    </item>
    <item>
      <title>Re: savestate issue with decisiontree train action cas</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/savestate-issue-with-decisiontree-train-action-cas/m-p/858623#M10433</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you try :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;saveState = {name='gb_yearly_kms_v3', caslib='PUBLIC', promote=true}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;?? ( if PUBLIC CASLIB is not disabled at your site )&lt;BR /&gt;Table (which is&amp;nbsp;&lt;SPAN&gt;an analytic store for the model as a binary object)&amp;nbsp;&lt;/SPAN&gt;should stay there across sessions!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise you can try :&amp;nbsp;&lt;/P&gt;
&lt;UL class="lia-list-style-type-disc"&gt;
&lt;LI&gt;Downloading the Store to the Local File System (PROC ASTORE download stmt)&lt;/LI&gt;
&lt;LI&gt;Uploading the Local Store from the Local File System (PROC ASTORE upload stmt)&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;BR,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2023 21:17:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/savestate-issue-with-decisiontree-train-action-cas/m-p/858623#M10433</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2023-02-13T21:17:46Z</dc:date>
    </item>
    <item>
      <title>Re: savestate issue with decisiontree train action cas</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/savestate-issue-with-decisiontree-train-action-cas/m-p/858679#M10434</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/60547"&gt;@sbxkoenk&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17969"&gt;@RalphAbbey&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;It works over sessions with the following code approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;...
   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;&lt;BR /&gt;&lt;BR /&gt;proc astore;&lt;BR /&gt;describe rstore=public.temp_GB_YEARLY_KMS epcode="/caslibs/busdev/yearly_epcode.sas";&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;proc astore;&lt;BR /&gt;score data=RISK.FOPERENT_DEC22_ETL_F1&lt;BR /&gt;rstore=public.temp_GB_YEARLY_KMS&lt;BR /&gt;out=RISK.FOPERENT_DEC22_ETL_FF12 &lt;BR /&gt;copyvars=( out_yearly_kms _PartInd_ from_gama_agg ) ;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In addition, I've implemented an override decision placed in the epcode, that's nice.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here for example, the business policy could mandate that special car models receive a customized scoring. It's the line after&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;method postScoreRecord();&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;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;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 09:18:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/savestate-issue-with-decisiontree-train-action-cas/m-p/858679#M10434</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2023-02-14T09:18:23Z</dc:date>
    </item>
  </channel>
</rss>

