/* 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;
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;
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)
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 Model 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);
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")
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 Model 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);