Configure SASPy

SASPy

SASPy is a Python module that allows one to use the best of Python and SAS in a single environment. With SASPy, data manipulation and preparation can be performed with Pandas while statistical procedures can be conducted in SAS. Essentially, SASPy allows you to bridge a Python session with a SAS session running in the background. The following instructions are to configure a locally installed version of SAS with Python (refer to the SASPy documentation for additional options).

Install SASPy

  1. Activate the Python virtual environment
  2. Install SASPy
pip install saspy

Configure SASPy

  1. Start a Python console or continue in the activated Python environment in PowerShell.
  2. Create a personal template cfg file. This creates a file that will be modified and used to configure SASPy. When executing the autocft.main() command, the path of the personal template file will be displayed upon execution. Make not of the path as this file will need to be modified.
# Load the autocfg function from the saspy module
from saspy import autocfg

# Create a template personal cfg file that is used to configure SAS sessions
autocfg.main() 
  1. Navigate to the path of the displayed directory
  2. Open the sascfg_personal.py file
  3. Modify the file to set the path of the Java run time executable
  4. Save and close the file
autogen_winlocal = {
    "java"      : "C:\\Program Files (x86)\\Java\\jre1.8.0_451\\bin\\java.exe",
    "encoding"  : "windows-1252"}

Check that SASPy can start a session

import saspy

sas = saspy.SASsession(cfgname = 'autogen_winlocal')