Post

Installing SASPy Kernel for Jupyter

This guide walks through the steps required to set up SASPy for use in Jupyter Notebooks and Jupyter Lab. By the end of this guide, you should be able to execute SAS code seamlessly from your Python environment.

Installing SASPy Kernel for Jupyter

Prerequisites

  1. Install Jupyter Lab
    1
    
      pip install jupyterlab
    
  2. Install SASPy
    1
    
      pip install saspy
    

Configuration Steps

  1. Set the Configuration File for SASPy
    • Copy a working example configuration file, such as sascfg_personal.py, and customize it for your setup. (An example is provided below.)
    • Ensure paths match your SAS installation
  2. Set the PATH Environment Variable
    • Ensure SAS and related binaries are included in your system’s PATH.
    • Update hosts file to resolve authentication issues:
      1
      2
      
       # In C:\Windows\System32\drivers\etc\hosts
       127.0.0.1 localhost view-localhost
      

Configuration Template

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# THIS IS AN EXAMPLE CONFIG FILE. PLEASE CREATE YOUR OWN sascfg_personal.py FILE USING THE APPROPRIATE TEMPLATES FROM BELOW
# SEE THE CONFIGURATION DOC AT https://sassoftware.github.io/saspy/install.html#configuration

SAS_config_names=['winlocal']

SAS_config_options = {'lock_down': False,
                      'verbose'  : True,
                      'prompt'   : True
                     }

SAS_output_options = {'output' : 'html5',       # not required unless changing any of the default
                      'style'  : 'HTMLBlue'}

default  = {'saspath'  : 'C:/Program Files/SASHome/SASFoundation/9.4/sas.exe'
            }

ssh      = {'saspath' : '/opt/sasinside/SASHome/SASFoundation/9.4/bin/sas_en',
            'ssh'     : '/usr/bin/ssh',
            'host'    : 'remote.linux.host',
            'encoding': 'latin1',
            'options' : ["-fullstimer"]
            }

# build out a local classpath variable to use below for Windows clients CHANGE THE PATHS TO BE CORRECT FOR YOUR INSTALLATION
cpW = "C:\\Program Files\\SASHome\\SASDeploymentManager\\9.4\\products\\deploywiz__94532__prt__xx__sp0__1\\deploywiz\\sas.svc.connection.jar"
cpW += ";C:\\Program Files\\SASHome\\SASDeploymentManager\\9.4\\products\\deploywiz__94532__prt__xx__sp0__1\\deploywiz\\log4j.jar"
cpW += ";C:\\Program Files\\SASHome\\SASDeploymentManager\\9.4\\products\\deploywiz__94532__prt__xx__sp0__1\\deploywiz\\sas.security.sspi.jar"
cpW += ";C:\\Program Files\\SASHome\\SASDeploymentManager\\9.4\\products\\deploywiz__94532__prt__xx__sp0__1\\deploywiz\\sas.core.jar"
cpW += ";C:\\ProgramData\\Anaconda3\\Lib\\site-packages\\saspy\\java\\saspyiom.jar"

iomlinux = {'java'      : '/usr/bin/java',
            'iomhost'   : 'linux.iom.host',
            'iomport'   : 8591,
            }

iomwin   = {'java'      : '/usr/bin/java',
            'iomhost'   : 'windows.iom.host',
            'iomport'   : 8591,
            }

winlocal = {'java'      : 'C:\\Program Files\\SASHome\\SASPrivateJavaRuntimeEnvironment\\9.4\\jre\\bin\\java.exe',
            'encoding'  : 'windows-1252',
            'classpath' : cpW
            }

winiomlinux = {'java'   : 'java',
            'iomhost'   : 'linux.iom.host',
            'iomport'   : 8591,
            }

winiomwin  = {'java'    : 'java',
            'iomhost'   : 'windows.iom.host',
            'iomport'   : 8591,
            }

winiomIWA  = {'java'    : 'java',
            'iomhost'   : 'windows.iom.host',
            'iomport'   : 8591,
            'sspi'      : True
            }

iomcom = {
    'iomhost' : 'mynode.mycompany.org',
    'iomport' : 8591,
    'provider': 'sas.iomprovider',
    'encoding': 'windows-1252'}

httpsviya = {'url'     : 'https://viya.deployment.com',
             'context' : 'Data Mining compute context',
             'authkey' : 'viya_user-pw',
             'options' : ["fullstimer", "memsize=1G"]
             }

httpviya = {'url'     : 'https://sastpw.rndk8s.openstack.sas.com:23456',
           #'port'    :  23456,   # can put different port here or ^ is it's not using the default port
            'context' : 'Data Mining compute context',
            'authkey' : 'viya_user-pw',
            'options' : ["fullstimer", "memsize=1G"]
            }

import os
os.environ["PATH"] += ";C:\\Program Files\\SASHome\\SASFoundation\\9.4\\core\\sasext\\sspiauth.dll"
os.environ["PATH"] += ";C:\\Program Files\\SASHome\\SASFoundation\\9.4\\core\\sasext"

Verification

Run the following Python code to confirm the setup:

1
2
3
4
5
6
import saspy
import saspy.sascfg

sas = saspy.SASsession(cfgname='winlocal')
cars = sas.sasdata("CARS", "SASHELP")
cars.describe()

Troubleshooting

Issue Encountered: "The application could not log on to the server 'localhost:0'. Integrated Windows authentication failed."

Solution:

  1. Refer to the SASPy troubleshooting documentation:
  2. Modify the hosts file:
    • Open the file located at C:\Windows\System32\drivers\etc\hosts.
    • Replace:
      1
      
       127.0.0.1 view-localhost
      

      with:

      1
      
       127.0.0.1 localhost view-localhost
      
This post is licensed under CC BY 4.0 by the author.