Python logo

Getting Started with SAS® Viya® for Python

The SAS Scripting Wrapper for Analytics Transfer (SWAT) package for Python is a Python 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. CAS can be running on a single machine (SMP) or in a distributed server (MPP). You can still retain the ease-of-use of Python on the client side to further post process CAS result tables.


SAS Scripting Wrapper for Analytics Transfer API
This native Python API provides direct access to SAS Cloud Analytics Services (CAS), using Python conventions and data structures to execute CAS actions. Data can be accessed and described as Pandas tables.

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

SAS GitHub

GitHub resources for developers

SAS has multiple Python-related repositories on github/sassoftware. Expand the section below for more information and links.

SAS GitHub repository links for Python

Python command-line tools that call the SAS Viya REST APIs - for SAS administrators.

The SAS Deep Learning Python (DLPy) package is the high-level Python APIs to SAS Deep Learning Toolkit on SAS Cloud Analytic Services (CAS). It allows users to build deep learning models using friendly Keras-like APIs.

The ESPPy module enables you to connect to a SAS ESP server, access information about the server, manage and construct projects, and interact with windows in your projects.

A Python interface module to the SAS System. It works with Linux, Windows, and mainframe SAS. It supports the sas_kernel project (a Jupyter Notebook kernel for SAS) or can be used on its own.

The SAS pipefitter package provides a Python API for developing pipelines for data transformation and model fitting as stages of a repeatable machine learning workflow in either SAS v9 or SAS Viya.

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

Companion to the book: SAS® Viya™: The Python Perspective by Kevin D. Smith and Xiangxiang Meng.

sasoptpy is a Python package providing a modeling interface for SAS Viya Optimization solvers.


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

Get Descriptive Statistics

The example below shows how to use the SUMMARY ACTION to get various descriptive statistics (minimum and maximum values, mean, standardDeviation, etc.) about a data table using SAS Cloud Analytics Services. This example requires that you have in-memory data to analyze.

$ python
In [1]: import swat
In [2]: conn = swat.CAS("", port, "myCasUserId", "myCasPassword")
In [3]: tbl = conn.read_csv(''
   ....:                     'sassoftware/sas-viya-programming/master/data/cars.csv',
   ....:                     casout='cars')
In [4]: out = conn.summary(table=tbl)
In [5]: out

 Descriptive Statistics for CARS
         Column      Min       Max      N  NMiss          Mean         Sum  \
 0         MSRP  10280.0  192465.0  428.0    0.0  32774.855140  14027638.0   
 1      Invoice   9875.0  173560.0  428.0    0.0  30014.700935  12846292.0   
 2   EngineSize      1.3       8.3  428.0    0.0      3.196729      1368.2   
 3    Cylinders      3.0      12.0  426.0    2.0      5.807512      2474.0   
 4   Horsepower     73.0     500.0  428.0    0.0    215.885514     92399.0   
 5     MPG_City     10.0      60.0  428.0    0.0     20.060748      8586.0   
 6  MPG_Highway     12.0      66.0  428.0    0.0     26.843458     11489.0   
 7       Weight   1850.0    7190.0  428.0    0.0   3577.953271   1531364.0   
 8    Wheelbase     89.0     144.0  428.0    0.0    108.154206     46290.0   
 9       Length    143.0     238.0  428.0    0.0    186.362150     79763.0   
             Std      StdErr           Var           USS           CSS  \
 0  19431.716674  939.267478  3.775916e+08  6.209854e+11  1.612316e+11   
 1  17642.117750  852.763949  3.112443e+08  5.184789e+11  1.329013e+11   
 2      1.108595    0.053586  1.228982e+00  4.898540e+03  5.247754e+02   
 3      1.558443    0.075507  2.428743e+00  1.540000e+04  1.032216e+03   
 4     71.836032    3.472326  5.160415e+03  2.215110e+07  2.203497e+06   
 5      5.238218    0.253199  2.743892e+01  1.839580e+05  1.171642e+04   
 6      5.741201    0.277511  3.296139e+01  3.224790e+05  1.407451e+04   
 7    758.983215   36.686838  5.760555e+05  5.725125e+09  2.459757e+08   
 8      8.311813    0.401767  6.908624e+01  5.035958e+06  2.949982e+04   
 9     14.357991    0.694020  2.061519e+02  1.495283e+07  8.802687e+04   
           CV      TValue          ProbT  
 0  59.288490   34.894059  4.160412e-127  
 1  58.778256   35.196963  2.684398e-128  
 2  34.679034   59.656105  3.133745e-209  
 3  26.834946   76.913766  1.515569e-251  
 4  33.275059   62.173176  4.185344e-216  
 5  26.111777   79.229235  1.866284e-257  
 6  21.387709   96.729204  1.665621e-292  
 7  21.212776   97.526890  5.812547e-294  
 8   7.685150  269.196577   0.000000e+00  
 9   7.704349  268.525733   0.000000e+00  

+ Elapsed: 0.0229s, user: 0.023s, sys: 0.003s, mem: 1.74mb
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