Back to Homepage


Setup SAS to Run R Code inside SAS

Feng Jiang
Last Updated: 2020-11-14

If you have a modern version of SAS and an up-to-date version of R on Windows, you are mostly likely to be able to run R code inside SAS. All you need to do for the setup is in the following two steps:

First, tell SAS to launch with the R functionality turned on. You can achieve this by either:

Second, tell SAS where to find R. You can achieve this by either:

Please change the R path according to the R version installed on your machine.

Now, you can run proc options option=RLANG; run; to check whether the R functionality has been turned on in SAS.

In summary, if you prefer not to change the SAS config file (sasv9.cfg), you only need to do the following two things:

  1. add -RLANG to the SAS command line,
  2. add the following two lines to your autoexec.sas:
    • options set=R_HOME='C:\Program Files\R\R-3.6.2'; . Please change the R path according to the R version installed on your machine.
    • proc options option=RLANG; run; . So that you can always see whether SAS is ready to run R when SAS is launched.

© 2020 fengjiang.me