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:
- SAS documentation: "Getting Started with SAS Viya for R" describes how to download and install the SWAT package and how to connect to a CAS server. It provides an example where computations (decision trees and decision forests) are run on the CAS server and the results are brought back to R to visualize by using ggplot.
- Brian Varney wrote a short "Getting Started" example for using the SWAT package in R.
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.
- 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.
- Configure SAS Viya to use the installation: Scott calls this "make R visible to SAS Viya."
- 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.
- Optionally configure access: You can limit who can access external languages such as R.
- 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.
The post Installing R for SAS IML in SAS Viya appeared first on The DO Loop.