Python SWAT Library
for developers
Getting Started with Python SWAT
The SAS Scripting Wrapper for Analytics Transfer (SWAT) package is a Python interface to SAS Cloud Analytic Services (CAS) (the centerpiece of the SAS Viya framework). Using SWAT, you can execute workflows of CAS analytic actions, then pull down the summarized data to further process on the client side in Python, or to merge with data from other sources using familiar Pandas data structures.
Features:
- full integration with Jupyter notebooks
- mimics much of the API of the Pandas package
- supports both natively compiled binary and pure Python REST clients
- code in Python and integrate with SAS
Try it for free as part of the SAS Viya Programming trial
- explore the capabilities of SAS Event Stream Processing
- self-contained programming environment - no installation
- use JupyterLab as an interface
- code with sample data and code demo scripts
Sample code
The sample code below establishs a connection and returns descriptive statistics on a table. To see further sample code, visit the samples page on GitHub.
Get Descriptive Statistics
>>> import saspy
>>> sas = saspy.SASsession()
SAS Connection established. Subprocess id is 3664
>>> cars = sas.sasdata( 'cars','sashelp')
>>> cars.describe()
Variable Label N NMiss Median Mean StdDev Min P25 P50 P75 Max
0 MSRP NaN 428 0 27635.0 32774.855140 19431.716674 10280.0 20329.50 27635.0 39215.0 192465.0
1 Invoice NaN 428 0 25294.5 30014.700935 17642.117750 9875.0 18851.00 25294.5 35732.5 173560.0
2 EngineSize Engine Size (L) 428 0 3.0 3.196729 1.108595 1.3 2.35 3.0 3.9 8.3
3 Cylinders NaN 426 2 6.0 5.807512 1.558443 3.0 4.00 6.0 6.0 12.0
4 Horsepower NaN 428 0 210.0 215.885514 71.836032 73.0 165.00 210.0 255.0 500.0
5 MPG_City MPG (City) 428 0 19.0 20.060748 5.238218 10.0 17.00 19.0 21.5 60.0
6 MPG_Highway MPG (Highway) 428 0 26.0 26.843458 5.741201 12.0 24.00 26.0 29.0 66.0
7 Weight Weight (LBS) 428 0 3474.5 3577.953271 758.983215 1850.0 3103.00 3474.5 3978.5 7190.0
8 Wheelbase Wheelbase (IN) 428 0 107.0 108.154206 8.311813 89.0 103.00 107.0 112.0 144.0
9 Length Length (IN) 428 0 187.0 186.362150 14.357991 143.0 178.00 187.0 194.0 238.0
>>>