sas viya from jupyter notebook by python modeling

SASPy Library
for developers

Getting started with SASPy

This module creates a bridge between Python and SAS 9.4. SASPy enables a Python developer, familiar with Pandas dataframes or SAS datasets, to leverage the power of SAS by connecting a Python process to a SAS 9.4 installation, where it will run SAS code. Features:

  • SAS code is generated by the supplied Python object and methods
  • Results return in various forms, including Pandas Data Frames
  • Run analytics and return graphics and data to the Python process
  • Convert data between SAS Data Sets and Pandas Data Frames
  • Supports local and remote connections
  • Interface with Jupyter notebooks or interactive and batch Python

Sample code

The sample code below establishes 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
>>>

Back to Top