Installing R for SAS IML in SAS Viya

0

Since 2008, SAS has supported an interface for calling R from the SAS/IML matrix language. Many years ago, I wrote blog posts that describe how to call R from PROC IML. For SAS 9.4, the process of installing R and calling R from PROC IML is documented in the SAS/IML User's Guide. Essentially, you install R on the same computer that runs the SAS Workspace Server so that SAS and R can communicate with each other. A SAS programmer can install R on his desktop machine that runs SAS; a SAS administrator can install R on a remote SAS Workspace Server.

Fast forward to 2023. Today, many SAS customers run SAS Viya in the cloud. If you want to call R from PROC IML in SAS Viya, R must be installed and deployed by a SAS Viya administrator. The steps to install R and deploy SAS are very different from the old SAS 9 days. This article provides a high-level overview.

Call SAS from R or call R from SAS?

In SAS 9.4, you can call R from SAS. In SAS Viya, you can call SAS actions from open-source languages, which means that you can also call SAS from R. This capability has been available since circa 2019 and can be used on Viya 3.5 as well as modern releases of Viya.

Thus, R programmers have a choice. Do you want to use R as a client to drive the flow of the program and occasionally call some computation in SAS? Or do you want to use SAS as a client and occasionally call computations in R? SAS supports both options.

Call SAS from R

If you are primarily an R programmer who wants to call a Viya action for a special computation (maybe a huge parallel computation in the cloud), you can use the SWAT package in R to connect to a CAS server and to call actions. SWAT stands for SAS Wrapper for Analytics Transfer, and SAS provides SWAT packages for several open-source languages, including R and Python. The following two resources can help you get started with calling CAS actions from the R language:

Call R from SAS

As mentioned earlier, the process of calling R from SAS is relatively straightforward in SAS 9.4. It is more complex in SAS Viya because both SAS and R must run "in the cloud." In practice, this means that SAS and R should be in the same container that is deployed. Thus, a SAS Viya administrator must build R, add it to a container, and deploy the container to the cloud. The main steps are as follows. They are taken from Scott McCauley's article, where you can find the details: This process assumes that you already have an existing SAS Viya deployment, and you want to add R to the deployment.

  1. Build R and packages: SAS provides a utility application called the "SAS Configurator for Open Source," which automates downloading, building, and installing R from source. The tool builds R and any packages from source on Linux. It puts the compiled files in a location, called the Persistent Volume Claim (PVC). Note: Scott's example installs both Python and R. In his example, the SAS Configurator for Open Source creates and executes a job called sas-pyconfig that (despite its name) installs both open-source products. He does not show an example that installs only R.
  2. Configure SAS Viya to use the installation: Scott calls this "make R visible to SAS Viya."
  3. Tell SAS Viya how to connect to R: You need to define some environment variables and SAS to enable R to be called by PROC IML or by other SAS products. This step is similar in SAS 9.4, but in SAS Viya the changes must be made to a YAML file.
  4. Optionally configure access: You can limit who can access external languages such as R.
  5. Rebuild the SAS deployment and apply the changes: To apply these changes, you must update your SAS Viya deployment.

The purpose of this article is to inform people that SAS provides tools to include R as part of a SAS Viya deployment. These steps were tested on the Viya release Stable 2022.12. I am not a SAS Viya administrator, so I confess that I have never implemented this process myself. If you have questions about this process, please post them to Scott McCauley's article. He is much more qualified than I am to answer questions about configuration and deployment.

Tags R Viya
Share

About Author

Rick Wicklin

Distinguished Researcher in Computational Statistics

Rick Wicklin, PhD, is a distinguished researcher in computational statistics at SAS and is a principal developer of SAS/IML software. His areas of expertise include computational statistics, simulation, statistical graphics, and modern methods in statistical data analysis. Rick is author of the books Statistical Programming with SAS/IML Software and Simulating Data with SAS.

Leave A Reply

Back to Top