1

How do I run R scripts from SAS without SAS-IML?

I am using SAS Enterprise Guide on a server. Since I have a background in R, I would like to be able to use R code to supplement the work I am doing in SAS.

The SAS license does not include IML. Thus, I cannot use proc iml. However, the server does have an R installation.

However, I've gathered from other sources—including this post as well as this post—that one can execute external scripts with SAS using the x command. In an email, someone indicated I can use call execute to execute "anything". In the same email, the person indicated that proc fcmp can build functions that execute Python.

This is all great to know, but I'm looking for a minimal reproducible example.

I'm fine with using .csv file intermediates for going back and forth between SAS and R.

For example, I am happy to build an R script that generates a .csv file which can later be read by SAS. I do not want to have to open and execute R externally though, I want SAS to execute the R script.

R script that SAS should run - simple_script_to_run_from_sas.r

df <- data.frame(
    a = c(1, 2, 3)
    , b = c("test", "one", "two")
    )

write.csv(
    df
    , paste0(getwd(), "/test.csv")
    , row.names = F
    )

What would the simplest SAS code be that would point to this R script and execute it?

A correct answer will be one that gives me simple SAS code that runs an R script. Bonus if similar code can be used to execute Python scripts (the server also has Python installed).

Jayden.Cameron
  • 499
  • 4
  • 17
  • Have you checked the link [here](https://www.listendata.com/2016/09/run-r-from-sas.html)? It seems to provide a suitable SAS macro for executing `Rscript` and maybe it could be used to make something more general. – Oliver Sep 21 '20 at 11:05

0 Answers0