I have an .R file that has a few functions stored in it. Functions as in FunctionName <- function(x). I am trying to write a SAS code that references this R file and can call and run one of the functions in the R file. Here is my code:
proc iml;
submit /R;
source(file = "C:/blah/My Documents/R/TheRFile.R")
function1("2014-05-25")
endsubmit;
quit;
And here is one of the functions in my R file:
function1 <- function(x){
refdate <- as.Date(x)
#MORE STUFF HERE
}
Essentially, the R functions in this R file take in a date as the parameter, and it uses this parameter to decide how to sort certain data files. When I run the SAS code I get:
NOTE: IML Ready
3393 submit /R;
3394 source(file = "C:/blah/My Documents/R/TheRFile.R")
3395 function1("2014-05-25")
3396 endsubmit;
ERROR: R: Error: could not find function "function1"
statement : SUBMIT at line 3393 column 1
3397 quit;
NOTE: Exiting IML.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IML used (Total process time):
real time 0.71 seconds
cpu time 0.01 seconds
I tried using the SAS MACRO command but that just got me even more confused. I think I explained what I want to do clearly. I understand the submit /R lets you run R code within that block of SAS code, but I am actually trying to access the functions of an external .R file. I've been pulling my hair out googling and there seems to be nothing on what I am trying to do. I have changed the names of the functions/variables/file locations but it should still make sense. Thanks.