Architecting, installing and maintaining your SAS environment

SAS and Python

Reply
Frequent Contributor
Posts: 118

SAS and Python

Hi,

 

How can I connect to SAS via Python? What should be installed on SAS side to be able to do this? Or is there any other thing that should be considered?

Super User
Super User
Posts: 8,174

Re: SAS and Python

In what sense do you mean "connect"?  For instance, you could just want to run programs in batch which is a simple command line call, or maybe you want to access data which may need a driver or specific software.  Give as much detail about what your doing/expect as possible.

Trusted Advisor
Posts: 1,424

Re: SAS and Python

Hello @Riana,

 

please give a look to this great post published by @ChrisHemedinger : https://blogs.sas.com/content/sasdummy/2017/04/08/python-to-sas-saspy/

 

It is about SASPy, the tool you can use to connect from Python to SAS.

 

 

Community Manager
Posts: 3,017

Re: SAS and Python

To expand on what @JuanS_OCS suggested:

 

SAS provides an open-source library called SASPy that allows you to connect your Python console or Jupyter Notebook to SAS.  You can find the library on the sassoftware GitHub account.  It works with SAS on any OS: Windows, Unix/Linux, even z/OS.

 

SASPy brings a "Python-ic" sensibility to this approach for using SAS. That means that all of your access to SAS data and methods are surfaced using objects and syntax that are familiar to Python users. This includes the ability to exchange data via pandas, the ubiquitous Python data analysis framework. And even the native SAS objects are accessed in a very "pandas-like" way.

 

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

More details, including a video with a demo, in this article: Introducing SASPy: Use Python code to access SAS

Frequent Contributor
Posts: 118

Re: SAS and Python

Posted in reply to ChrisHemedinger

Thanks @ChrisHemedinger for you reply.

 

I'm working on a presentation about Jupyter notebook and SAS and how it works(for dummies :-)). I need to create a demonstarion of connection between SAS servers, jupyter notebook, saspy,... that how they communicate in a simple way. Is there such document or link that can be used for this purpose? 

Community Manager
Posts: 3,017

Re: SAS and Python

@Riana - are you looking for something like an architecture/conceptual diagram? I'm not aware of one that exists today, though it's a good idea to have one.  When you draw one out, let us know Smiley Wink

 

There is some good information in this article by @EdwardJin.

Frequent Contributor
Posts: 89

Re: SAS and Python

@Riana I am not sure if this answers your question but I have once made a simplified illustration on how Jupyter works for a presentation I gave.

Jupyter_HowDoesItWork.PNG

The "kernel" node that is shown in the image is any Jupyter Kernel of which one is the SAS kernel
The link between the Notebook Server node and the Kernel node links to zeromq

The link between the Notebook Server node and the Notebook File node links to JSON

 

Ask a Question
Discussion stats
  • 6 replies
  • 450 views
  • 11 likes
  • 5 in conversation