Hi everyone,
Is it possible to import a gradient boosting model developed in R inside SAS real-time decision maker?
We can export it either a xgboost binary files or as a bunch of if-then-else statements in SQL .
thanks
The IF-THEN-ELSE are the same as normal DS, but the code that wraps around them in DS2 is different to DATA step - I've included a mock up below.
As for the Lookups, for very small table we can use the Cross Table node inside a diagram, but for the size you mention its too large. We can lookup data from a table stored in a data set or database using a Data Process inside the diagram. This is a high performing query and can use a very large table (based on the database). But for this I would probably go with coded rules.
Cheers
James
package GBM_Model/overwrite=yes;
/* declare a logger */
declare package logger m_logger('morglum.GMB_Model');
/* set logging methods */
method trace(varchar(32767) msg);
m_logger.log(2, msg);
end;
method debug(varchar(32767) msg);
m_logger.log(3, msg);
end;
method err(varchar(32767) msg);
m_logger.log(6, msg);
end;
method isTraceEnabled() returns int;
return m_logger.islevelactive(2);
end;
method isDebugEnabled() returns int;
return m_logger.islevelactive(3);
end;
/* execute method which gets called by RTDM - the inputs here need to be defined in the RTDM Activity and values passed from the decision flow */
method execute( char gender
, char education
, int age_years
, in_out double predicted_wages
);
/* log messages */
if isDebugEnabled() then
debug('Entered Execute Method');
/* optional trace messages - maybe not great if there are 100s of inputs */
if isTraceEnabled() then
do;
trace('Input gender:' gender);
trace('Input education:' education);
trace('Input age_years:' age_years);
end;
/* Model IF-THEN-ELSE rules */
if (gender EQ 'Male' and education = 'university' and age_years > 50) then
/* if only one output variable the wont need a do block, just set the variable after then on the line above */
do;
/* set outputs */
predicted_wages = 45001.10 ;
end;
else if (gender EQ 'Female' and education = 'university' and age_years > 50) then
do;
/* set outputs */
predicted_wages = 45001.10 ;
end;
else
/* final block */
do;
predicted_wages = 0.0;
end;
/* End of Model IF-THEN-ELSE rules */
/* log messages */
if isDebugEnabled() then
debug('Finished Execute Method');
if isTraceEnabled() then
do;
trace('Output predicted_wages:' predicted_wages);
end;
end;
end;
endpackage;
While working with another customer to use the sample code provided, we had to make a few modifications to make it work in an RTDM 6.5 SAS Process.
Here is the revised sample code:
package GBM_Model/overwrite=yes;
/* declare a logger */
declare package logger m_logger('morglum.GBM_Model');
/* set logging methods */
method trace(varchar(32767) msg);
m_logger.log(2, msg);
end;
method debug(varchar(32767) msg);
m_logger.log(3, msg);
end;
method err(varchar(32767) msg);
m_logger.log(6, msg);
end;
method isTraceEnabled() returns int;
return m_logger.islevelactive(2);
end;
method isDebugEnabled() returns int;
return m_logger.islevelactive(3);
end;
/* execute method which gets called by RTDM - the inputs here need to be defined in the RTDM Activity and
values passed from the decision flow */
method execute( char(10) gender,
char(30) education,
int age_years,
in_out double predicted_wages
);
/* log messages */
if isDebugEnabled() then
debug('Entered Execute Method');
/* optional trace messages - maybe not great if there are 100s of inputs */
if isTraceEnabled() then
do;
trace('Input gender:' || gender);
trace('Input education:' || education);
trace('Input age_years:' || age_years);
end;
/* Model IF-THEN-ELSE rules */
if (gender EQ 'Male' and education = 'university' and age_years > 50) then
/* if only one output variable the wont need a do block, just set the variable after then on the line above */
do;
/* set outputs */
predicted_wages = 45001.10 ;
end;
else if (gender EQ 'Female' and education = 'university' and age_years > 50) then
do;
/* set outputs */
predicted_wages = 45002.10 ;
end;
else
/* final block */
do;
predicted_wages = 0.0;
end;
/* End of Model IF-THEN-ELSE rules */
/* log messages */
if isDebugEnabled() then
debug('Finished Execute Method');
if isTraceEnabled() then
do;
trace('Output predicted_wages:'|| predicted_wages);
end;
end;
endpackage;
run;
quit;
/* code to test with your Federation Server via SAS Studio or EG */
proc ds2 nolibs NOPROMPT="driver=remts;server=your-fed-server;port=24141;protocol=bridge;uid=your-user;pwd=your-pw;conopts=(driver=ds2;conopts=(DSN=BASE_DSN))";
data _null_;
method run();
declare package GBM_Model GBMM();
declare double pw;
GBMM.execute('Male', 'university', 51, pw);
put pw=;
GBMM.execute('Female', 'university', 64, pw);
put pw=;
GBMM.execute('Male', 'high school', 51, pw);
put pw=;
end;
enddata;
run;
quit;
thanks for this update!
I am a typical base SAS user and my RTDM person has never used proc DS2 either.
My question for today is : where does this code go? I've followed a proc ds2 tutorial (https://www.lexjansen.com/sesug/2017/HOW-190.pdf) where you run proc ds2 inside SAS EG, but where would the code live in the context of SAS RTDM? Is there a guide somewhere on how to call proc ds2 from SAS RTDM?
thanks
Simon
Want to review SAS CI360? G2 is offering a gift card or charitable donation for each accepted review. Use this link to opt out of receiving anything of value for your review.
Listen to the Reimagine Marketing podcast
Assess your marketing efforts with a free tool
SAS Customer Intelligence Learning Subscription (login required)
Compatibility notice re: SAS 9.4M8 (TS1M8) or later
SAS' Peter Ansbacher shows you how to use the dashboard in SAS Customer Intelligence 360 for better results.
Find more tutorials on the SAS Users YouTube channel.
Want to review SAS CI360? G2 is offering a gift card or charitable donation for each accepted review. Use this link to opt out of receiving anything of value for your review.
Listen to the Reimagine Marketing podcast
Assess your marketing efforts with a free tool
SAS Customer Intelligence Learning Subscription (login required)
Compatibility notice re: SAS 9.4M8 (TS1M8) or later