DATA Step, Macro, Functions and more

Announcing SASPy: programming SAS from Python

Community Manager
Posts: 3,356

Announcing SASPy: programming SAS from Python

I'm cross-posting this announcement from @FriedEgg who shared it on SAS-L.  I love the SAS-L list, but I don't want them to get all of the scoop on this exciting news for Python coders who use SAS (or is it SAS programmers who use Python?).  Quoting FriedEgg here:

Just wanted to share a very exciting release from SAS on Github that happened just recently.  This is a fantastic expansion of functionality and a huge step forward for those interested in Open Source Integration with SAS.  I, personally, am most happy to see all of the expanded connection options.


the Real saspy

This release changes almost everything about saspy. In version 1 saspy only had a submit method to enable the sas_kernel. It now has much much more.

Here are the highlights:

  • Transfer of SAS datasets and Pandas dataframes
  • SAS Data object which provides methods for working with data in SAS. Here is a few of the methods (see the doc for the complete list)
    • Graphics (histogram, barchart, heatmap)
    • Partitioning data
    • Scoring data
    • Assessing models
    • Filtering (where, keep, drop)
  • SAS Result object to store and display ODS results from modeling and data analysis
  • Support for connections to SAS Grid Manager, PC SAS, and any other SAS IOM interface (even the mainframe)
  • Analytical modeling methods
    • Statistics
    • Machine Learning
    • Econometric Time Series (ETS)
    • Quality Control
  • Documentation using Sphinx:


We'll have more documentation and articles coming on this, including plenty of content featured from SAS Global Forum in just a couple of weeks.  In the meantime -- go check out the SAS Software GitHub and play with SASPy!  It works with SAS 9.4 on Windows, Unix, and even the mainframe.  


(Kudos to the developers from SAS: @Jared and Tom Weber.  You'll see their fingerprints all over the GitHub commits.)



Community Manager
Posts: 3,356

Re: Announcing SASPy: programming SAS from Python

Posted in reply to ChrisHemedinger

If you want to learn more about SASPy, I've summarized the news in this blog post.  The blog also contains a video explanation and demo from @Jared, one of the SASPy developers.

Occasional Contributor
Posts: 11

Re: Announcing SASPy: programming SAS from Python

Posted in reply to ChrisHemedinger

Robot wink

These comments are for other SAS Programmers who want to run saspy in Anaconda3 in Windows 10 using a local BASE SAS installation...


Download Anaconda and install using the recommended option

Note...Your computer may have mutiple versions of Python installed and configured various ways.The Anaconda distribution takes care of most of the setup problems by installing all this within an App

Verify the following:
(base) C:\Users\YOURWINDOWSNAME>python --version
Python 3.6.3 :: Anaconda custom (64-bit)

From the Anaconda DOS prompt (It's an app in your Anaconda3 folder): (base) C:\> pip install saspy
That'll install the saspy package. If you want the SAS kernel too, type pip install sas_kernel. Then you will be able to use the SAS kernel in Jupyter (i.e. write SAS code from a Jupyter notebook - cool eh?)


Now that the saspy package is installed, you have to add the directory that contains the file sspiauth.dll to our Path variable. This file is located at ~\SASHome\SASFoundation\9.4\core\sasext

Update your Path in Windows 10...You need to have Admin rights
In Windows 10 > From the Power User Task Menu > click System > Advanced Settings > Environment Variables > Edit a variable labelled "Path". There are already several folders in a list displayed - Add ~\SASHome\SASFoundation\9.4\core\sasext to the list.

As a check, if you open the cmd line in DOS and type c:\>path you will see something like:


Or, Open Base SAS and run the following to find the PATH – The results will be the same
data _null_;
put x;

Now you use IDLE to edit saspy.cfg - It's in C:\Users\YOURWINDOWSNAME\AppData\Local\Continuum\Anaconda3 (somewhere...).
You will need to go to ~\SAS\SASHome\SASDeploymentManager\9.4\products\~ and make updates according to the versions you see. Note that '\\' means '\' when you are setting paths in your Python editor

The saspy.cfg file looks like
…scroll down to the config names below and make some changes


…scroll down to the path files below

# build out a local classpath variable to use below for Windows clients
cpW = "F:\\SAS\\SASHome\\SASDeploymentManager\\9.4\\products\\deploywiz__NUMBER__prt__xx__sp0__1\\deploywiz\\sas.svc.connection.jar"
cpW += ";F:\\SAS\\SASHome\\SASDeploymentManager\\9.4\\products\\deploywiz__NUMBER__prt__xx__sp0__1\\deploywiz\\log4j.jar"
cpW += ";F:\\SAS\\SASHome\\SASDeploymentManager\\9.4\\products\\deploywiz__NUMBER__prt__xx__sp0__1\\deploywiz\\"
cpW += ";F:\\SAS\\SASHome\\SASDeploymentManager\\9.4\\products\\deploywiz__NUMBER__prt__xx__sp0__1\\deploywiz\\sas.core.jar"
cpW += ";C:\\ProgramData\\Anaconda3\\Lib\\site-packages\\saspy\\java\\saspyiom.jar"

…cpW is aliased as winlocal (see below)

winlocal = {'java' : 'java',
'encoding' : 'windows-1252',
'classpath' : cpW

The following Python code will start a session: sas = saspy.SASsession(cfgname='winlocal')

You can test your installation using
import saspy
import saspy.sascfg
sas = saspy.SASsession(cfgname='winlocal')
cars = sas.sasdata("CARS","SASHELP")

and you should see a SASHELP data set about cars.


 - Bread Crumbs and Circuses for all

Bread Crumbs and Circuses for All
Ask a Question
Discussion stats
  • 2 replies
  • 2 in conversation