R logo

Integrate SAS with the R Language

Getting started with SAS and R integration

Combine R language functions with SAS through various code libraries. These packages allow you to:

  • Load, import, and profile data using an integrated development environment (IDE) or REST APIs.
  • Cleanse, prepare, and transform your data.
  • Use functions to manage and provide governance for data assets and their relationships.
Programming code abstract technology background of software developer and computer script

R SWAT
The SAS Scripting Wrapper for Analytics Transfer (SWAT) package is the R client to SAS Cloud Analytic Services (CAS).  It allows users to execute CAS actions and process the results all from R.

Key features: 
 •
 load and analyze data sets of any size on your desktop or in the cloud  
 •
execute workflows of CAS analytic actions
 • work with the results of the data analysis using familiar techniques in R

SAS® Enterprise Miner: Terms

SAS Enterprise Miner open source integration node
The Open Source Integration node enables you to write code in the R language inside SAS Enterprise Miner.

Key features: 
 • 
use R in SAS Enterprise Miner
 • call R from SAS to use as a complimentary resource
 • build predictive models

>> Integrating R Code into SAS Enterprise Miner video tutorial

IML 3

SAS/IML software and R
IML is a programming language for statistical computations, focusing on algorithms using matricies and vectors.

Key features: 
 • 
call R functions, packages, and graphics
 • create user defined functions to extend functionality
 • exchange data and matricies using built-in routines

>> Calling R Procedures from SAS/IML® Software video turtorial
>> SAS Programming for R users course materials on GitHub

Sample code

The example below shows how to use the cas.simple.summary function to get various descriptive statistics (minimum and maximum values, mean, standard deviation, etc.) about a data table using SAS Cloud Analytics Services. The sample program reads a CSV file and transfers the data to the server and computes the summary statistics.

Get Summary Statistics


library("swat")
conn = CAS("myhost.example.com", port = myPort, username = "myUserName", password = "myPassWord")
tbl = cas.read.csv(conn, file = 'https://raw.githubusercontent.com/sassoftware/sas-viya-programming/master/data/cars.csv')
out = cas.simple.summary(tbl)
out

/* The sample program prints the summary statistics to standard output: */

$Summary
        Column     Min      Max   N NMiss         Mean        Sum          Std       StdErr          Var
1         MSRP 10280.0 192465.0 428     0 32774.855140 14027638.0 19431.716674 939.26747766 3.775916e+08
2      Invoice  9875.0 173560.0 428     0 30014.700935 12846292.0 17642.117750 852.76394866 3.112443e+08
3   EngineSize     1.3      8.3 428     0     3.196729     1368.2     1.108595   0.05358595 1.228982e+00
4    Cylinders     3.0     12.0 426     2     5.807512     2474.0     1.558443   0.07550679 2.428743e+00
5   Horsepower    73.0    500.0 428     0   215.885514    92399.0    71.836032   3.47232565 5.160415e+03
6     MPG_City    10.0     60.0 428     0    20.060748     8586.0     5.238218   0.25319881 2.743892e+01
7  MPG_Highway    12.0     66.0 428     0    26.843458    11489.0     5.741201   0.27751141 3.296139e+01
8       Weight  1850.0   7190.0 428     0  3577.953271  1531364.0   758.983215  36.68683841 5.760555e+05
9    Wheelbase    89.0    144.0 428     0   108.154206    46290.0     8.311813   0.40176665 6.908624e+01
10      Length   143.0    238.0 428     0   186.362150    79763.0    14.357991   0.69401970 2.061519e+02
            USS          CSS        CV    TValue         ProbT
1  6.209854e+11 1.612316e+11 59.288490  34.89406 4.160412e-127
2  5.184789e+11 1.329013e+11 58.778256  35.19696 2.684398e-128
3  4.898540e+03 5.247754e+02 34.679034  59.65611 3.133745e-209
4  1.540000e+04 1.032216e+03 26.834946  76.91377 1.515569e-251
5  2.215110e+07 2.203497e+06 33.275059  62.17318 4.185344e-216
6  1.839580e+05 1.171642e+04 26.111777  79.22923 1.866284e-257
7  3.224790e+05 1.407451e+04 21.387709  96.72920 1.665621e-292
8  5.725125e+09 2.459757e+08 21.212776  97.52689 5.812547e-294
9  5.035958e+06 2.949982e+04  7.685150 269.19658  0.000000e+00
10 1.495283e+07 8.802687e+04  7.704349 268.52573  0.000000e+00



Back to Top