Blue background
r-logo

Getting Started with SAS® Viya for R

The SAS Scripting Wrapper for Analytics Transfer (SWAT) package for R is a R interface to SAS Cloud Analytic Services (CAS) which is the centerpiece of the SAS Viya framework. With this package, you can load data into memory and apply CAS actions to transform, summarize, model and score the data. Result tables from the actions are a superclass of data frame, enabling you to apply your existing R programming skills to further post-process CAS result tables.

 

 

 

Documentation

SAS Scripting Wrapper for Analytics Transfer API
This native R package provides direct access to SAS Cloud Analytics Services (CAS), using R syntax conventions and data structures to execute CAS actions. Data can be exchanged to and from R data frames.

Getting Started with SAS Viya for R
Learn the concepts and capabilities of the R API for SAS Viya.

 


Examples

Select a sample below and copy and paste into your application.

Get Descriptive Statistics

The example below shows how to use the cas.simple.summary function 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.

Run the Summary Action

After installing the SAS R Client interface for SAS Viya


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


SAS Viya logo

One underlying code base, programmable in the language of your choice.

Learn more about SAS Viya

SAS Viya logo

Engage in the discussions happening around the power of SAS® Viyaand discover what it can do for you.

Join our Coding on SAS Viya Community

Back to Top