Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Editing SAS config files to execute R (making SAS play well with others)

There are many things that R just does better. Hence, I am trying to set my system up so I can execute R commands from within SAS using the [submit /R;] and [endsubmit;] commands. However I need some help getting my config files set up properly to do this.

First Steps (to allow SAS to read the R language):

I checked to see if my system was set up to read the R language (code below).

proc options option=rlang;
run;

I got the following in my log:

SAS (r) Proprietary Software Release 9.3  TS1M0

NORLANG           Do not support access to R language interfaces

This meant I needed to add the -RLANG option to the config file. I did that. Below is an example of my config file (C:\Program Files\SASHome\SASFoundation\9.3\sasv9.cfg):

-RLANG
-config "C:\Program Files\SASHome\SASFoundation\9.3\nls\en\sasv9.cfg"

(NOTE: the -RLANG had to be above the config reference for this to be recognized properly.)

And the resulting output in my log after re-opening enterprise guide and re-running the proc options code above:

SAS (r) Proprietary Software Release 9.3  TS1M0

RLANG             Support access to R language interfaces

Issue (specific to Enterprise Guide?):

I am using SAS 9.3 and R 2.15.2, so according to this (http://blogs.sas.com/content/iml/2013/09/16/what-versions-of-r-are-supported-by-sas/) these versions are compatible.

However, I execute SAS through Enterprise Guide 4.3 (I like organization better). It appears that Enterprise Guide may require some additional stuff in the config file to allow R to run and recognize where it is on my computer.

For example, I try running the following code:

Proc iml;
  submit /R;
        directory <- "C:\\Data\\Filepath"
        FILEpattern1 <- "Fall 12-13.xlsx"

        setwd(directory)
        filenames1 <- list.files(pattern=FILEpattern1)
  endsubmit; 

And I get the following error:

15         Proc iml;
NOTE: IML Ready
16         submit /R;
17         directory <- "C:\\Data\\Filepath"
18         FILEpattern1 <- "Fall 12-13.xlsx"
19         
20         setwd(directory)
21         filenames1 <- list.files(pattern=FILEpattern1)
22         endsubmit;
ERROR: SAS could not initialize the R language interface.

statement : SUBMIT at line 16 column 1

According to this thread (https://communities.sas.com/thread/34758), individuals using Enterprise Guide also need to define where R_Home is on their computer. The thread discusses changing something in sasenv_local but I need more specific directions.

Any suggestions or advice on how to get this working?

like image 832
ESmith5988 Avatar asked Oct 22 '13 18:10

ESmith5988


1 Answers

If the issue is solely defining R_HOME in the local environment variables, you have at least three options. You can add this to your config file if you have access to that (the file referenced in -config in the OP):

-SET R_HOME "r_home location"

You could use options set to do the same thing (options set=R_HOME='r_home location';) if you don't have permission to modify your config file, as well.

You also should be able to modify the environment variable in Windows directly, by going to My Computer, right click-properties, Advanced, Environment Variables, and setting it there. Again, this requires administrative rights.

See this paper for more information.

As noted by the OP. R_HOME needs to be set to the base directory for R (such as c:\program files\R), not to the \bin folder or any other particular location.

like image 120
Joe Avatar answered Oct 21 '22 11:10

Joe