How to use PROC R in SAS

The number of languages and tools for Statistical Analysis has been rapidly increasing in recent times. Every tool being developed however has it’s own pros and cons. For example, SAS, a very popular commercial tool is easy to use, but expensive; R, on the other hand, is free and powerful, but requires programming/tool expertise, due to lack of accountability and minimum support.

30 July


Continued efforts towards enabling usage of multiple languages in a single tool has allowed users proficient in a particular technology/language to also benefit from the advantages of other languages. To mention a few are the R packages to integrate C++ and SQL, Python package to integrate R, SAS package to integrate SQL.

Similar to PROC SQL, the programming interface that enables writing SQL scripts within SAS codes, PROC R is developed as an interface between R and SAS. It Enables Native R Programming in the Base SAS Environment. Using Proc_R, the SAS users can access the extensive statistical and visualization capabilities of R.

The Proc R SAS Macro was developed by Xin Wei, who published a paper in Jan 2012 in the “Journal of Statistical Software” explaining its implementation and usage.

Setup for Proc_R:

  1. The Proc_R.sas library can be downloaded from the link: https://www.jstatsoft.org/v46/c02
  2. Save the file.
  3. Edit the file – Search for rpath option. Change its value to point to the absolute location of your R executable.

SAS Syntax to use Proc_R:
%include “C:\Proc_R.sas”;
%Proc_R (SAS2R =, R2SAS =);
******************************
***Your R Code Here***
******************************
;
%Quit;
Explanation:

Include the Proc R package in your SAS code. Specify the absolute or relative path of the Proc_R.sas source file.

The Proc_R macro contains two macro variables as input parameters called SAS2R (that defines the mechanism to convert SAS datasets to R dataframes) and R2SAS (that defines the mechanism to convert R dataframes into SAS datasets).

Write your R code snippet within the Macro.

The comfortable use of R in SAS has greatly simplified the analytics procedure, however the above Macro works only for windows and the updated Proc_R macro for the latest base SAS versions are also not available yet. However the mentioned drawbacks are negligible compared to the advantages the interface provides.

Reference:
For more coding examples and implementation of functionalities of Proc_R, you can refer to the paper written by Xin Wei :
https://www.jstatsoft.org/v46/c02/paper
Related Posts:
The Power of R – And Why it’s an Essential Skill for Data Analysts
Examples of How R is Used
Top 8 Reasons to Learn SAS

Interested in learning about other Analytics and Big Data tools and techniques? Click on our course links and explore more.
Jigsaw’s Data Science with SAS Course – click here.
Jigsaw’s Data Science with R Course – click here.
Jigsaw’s Big Data Course – click here.

Related Articles

loader
Please wait while your application is being created.
Request Callback