/* Define the libref to the SAS input data set. */ libname libref "path-to-input-data-set"; /* Use PROC IML to export the SAS input data set to the R input data set. */ proc iml; run ExportDatasetToR("input-data-set" , "R-matrix-input"); /* Submit the model-fitting R code. */ submit /R; attach(R-matrix-input) # ----------------------------------------------- # FIT THE MODEL # ----------------------------------------------- model-name<- model-fitting-function # ----------------------------------------------- # SAVE THE PARAMETER ESTIMATE TO LOCAL FILE OUTMODEL.RDA # ----------------------------------------------- save(model-name, file="path/outmodel.rda") endsubmit; run; quit;
is the path to the library where the input data set is stored.
is the name of the input data set.
is the R input data.
is the name of the model.
is the R formula that is used to fit the model.
is the path to where outmodel.rda is to be stored.
libname mmsamp "!sasroot\mmcommon\sample"; proc iml; run ExportDatasetToR("mmsamp.hmeq_train" , "mm_inds"); submit /R; attach(mm_inds) # ----------------------------------------------- # FIT THE LOGISTIC MODEL # ----------------------------------------------- logiten<- glm(BAD ~ VALUE + factor(REASON) + factor(JOB) + DEROG + CLAGE + NINQ + CLNO , family=binomial) # ----------------------------------------------- # SAVE THE PARAMETER ESTIMATE TO LOCAL FILE OUTMODEL.RDA # ----------------------------------------------- save(logiten, file="c:/RtoMMfiles/outmodel.rda") endsubmit; run; quit;
save(model-name, file="path/outmodel.rda")
is the name of the R model.
is the system path to the location where outmodel.rda is stored.
save(logiten, file=”c:/temp/outmodel.rda")
attach(R-matrix-input) # ----------------------------------------------- # LOAD THE OUTPUT PARAMETER ESTIMATE FROM FILE OUTMODEL.RDA # ----------------------------------------------- load('&_mm_scorefilesfolder/outmodel.rda') # ----------------------------------------------- # SCORE THE MODEL # ----------------------------------------------- score<- predict(model-name, type="response", newdata=R-matrix-input) # ----------------------------------------------- # MERGING PREDICTED VALUE WITH MODEL INPUT VARIABLES # ----------------------------------------------- mm_outds <- cbind(R-matrix-input, score)
is the name of the input R matrix file that you specified in the ExportDatasetToR function in the IML procedure. See Build an R Model.
is the output variable. The value for score must match the output variable that is defined in modeloutput.sas7bdat and outputvar.xml.
is the name of the R model. The value of model-name must match the R save function model-name argument that is specified in the outmodel.rda file.
attach(mm_inds) # ----------------------------------------------- # LOAD THE OUTPUT PARAMETER ESTIMATE FROM FILE OUTMODEL.RDA # ----------------------------------------------- load('&_mm_scorefilesfolder/outmodel.rda') # ----------------------------------------------- # PREDICT # ----------------------------------------------- score<- predict(logiten, type="response", newdata=mm_inds) # ----------------------------------------------- # MERGE THE PREDICTED VALUE WITH MODEL INPUT VARIABLES # ----------------------------------------------- mm_outds <- cbind(mm_inds, score)
filename tmp catalog "sashelp.modelmgr.mm_include.source"; %include tmp; filename tmp; data work.mm_score_task_information; length role $ 8; length name $ 80; length value $ 200; role = "input"; name = "importedData"; value = "&_mm_inputds"; output; role = "input"; name = "modelID"; value = "&_mm_modelID"; output; role = "output"; name = "exportedData"; value = "&_mm_outputds"; output; role = "input"; name = "dataRole"; value = "output-variable-name"; output; role = "input"; name = "p_Target"; value = "output-variable-name"; output; run; /* mm_r_model_score_main is a SAS Decision Manager process flow that is used to run */ /* R model scripts using PROC IML. */ %mmbatch(task=mm_r_model_score_main, taskprops= mm_score_task_information);
is the output variable that is defined in modeloutput.sas7bdat or modeloutput.xml.
role = "input"; name = "_mm_trace"; value = "ON"; output;
attach(R-matrix-input) # ----------------------------------------------- # FIT THE LOGISTIC MODEL # ----------------------------------------------- model-name<- model-fitting-function # ----------------------------------------------- # SAVE THE OUTPUT PARAMETER ESTIMATE TO LOCAL FILE OUTMODEL.RDA # ----------------------------------------------- save(model-name, file="&_MM_TrainResultFolder/outmodel.rda")
is the name of the R matrix that is specified in the ExportMatrixToR function that is used to build a model using the IML procedure.
is the name of the R model.
is an R model fitting function, such as lm() or glm().
attach(mm_inds) # ----------------------------------------------- # FIT THE LOGISTIC MODEL # ----------------------------------------------- logiten<- glm(BAD ~ VALUE + factor(REASON) + factor(JOB) + DEROG + CLAGE + NINQ + CLNO , family=binomial) # ----------------------------------------------- # SAVE THE OUTPUT PARAMETER ESTIMATE TO LOCAL FILE OUTMODEL.RDA # ----------------------------------------------- save(logiten, file="&_MM_TrainResultFolder/outmodel.rda")
filename tmp catalog "sashelp.modelmgr.mm_include.source"; %include tmp; filename tmp; data work.mm_train_task_information; length role $ 8; length name $ 80; length value $ 200; role = "input"; name = "trainData"; value = "&_mm_inputds"; output; role = "input"; name = "modelID"; value = "&_mm_modelID"; output; run; /* mm_r_model_train_main is a SAS Decision Manager process flow that is used to run */ /* R model scripts using PROC IML. */ %mmbatch(task=mm_r_model_train_main, taskprops= mm_train_task_information);
role = "input"; name = "_mm_trace"; value = "ON"; output;