Using Python to work with SAS Viya and CAS

One of the big benefits of SAS Viya is how approachable it is for programmers of other languages. You don't have to learn SAS in order to become productive quickly. We've seen a lot of interest from people who code in Python, maybe because that language has become known for its application in machine learning. SAS has a new product called SAS Visual Data Mining and Machine Learning. And these days, you can't offer such a product without also offering something special to those Python enthusiasts.

Update: SAS now offers a free trial for developers -- scroll down here for more details!

Introducing Python SWAT

And so, SAS has published the Python SWAT project (where "SWAT" stands for the SAS scripting wrapper for analytical transfer. The project is a Python code library that SAS released using an open source model. That means that you can download it for free, make changes locally, and even contribute those changes back to the community (as some developers have already done!). You'll find it at github.com/sassoftware/python-swat.

SAS developer Kevin Smith is the main contributor on Python SWAT, and he's a big fan of Python. He's also an expert in SAS and in many programming languages. If you're a SAS user, you probably run Kevin's code every day; he was an original developer on the SAS Output Delivery System (ODS). Now he's a member of the cloud analytics team in SAS R&D. (He's also the author of more than a few conference papers and SAS books.)

Kevin enjoys the dynamic, fluid style that a scripting language like Python affords - versus the more formal "code-compile-build-execute" model of a compiled language. Watch this video (about 14 minutes) in which Kevin talks about what he likes in Python, and shows off how Python SWAT can drive SAS' machine learning capabilities.

New -- but familiar -- syntax for Python coders

The analytics engine behind SAS Viya is called CAS, or SAS Cloud Analytic Services. You'll want to learn that term, because "CAS" is used throughout the SAS documentation and APIs. And while CAS might be new to you, the Python approach to CAS should feel very familiar for users of Python libraries, especially users of pandas, the Python Data Analysis Library.

CAS and SAS' Python SWAT extends these concepts to provide intuitive, high-performance analytics from SAS Viya in your favorite Python environment, whether that's a Jupyter notebook or a simple console. Watch the video to see Kevin's demo and discussion about how to get started. You'll learn:

How to connect your Python session to the CAS server

How to upload data from your client to the CAS server

How SWAT extends the concept of the DataFrame API in pandas to leverage CAS capabilities

How to coax CAS to provide descriptive statistics about your data, and then go beyond what's built into the traditional DataFrame methods.

Try it -- for free! -- in your browser

Want to get your hands on this? With just a couple of clicks, you can sign into the SAS Viya Developer Free Trial. You sign in with your SAS.com profile (the same one you use in SAS Support Communities or to access SAS e-learning). The trial environment lets you test-drive SAS Viya using Python or R in a Jupyter notebook, or with SAS programming using SAS Studio. When you sign up and click through to the trial, you'll have your own session that you can use for the next 8 hours -- plenty of time to kick the tires.

The trial environment includes all of the sample data and code that you need to get a feel for what it's like to code with CAS. You can find all of the API reference documentation at the SAS for Developers site. SAS developer Jared Dean narrates this great demo/tutorial that you can watch or follow along with during your experience.

Learn more about SAS Viya and Python

There are plenty of helpful resources to help you learn about using Python with SAS Viya:

Kevin wrote a book (with coauthor Xiangxiang "X2" Meng) about this topic: SAS Viya: The Python Perspective. The authors also shared the sample code from the book on GitHub. Check out the many sample Python notebooks (including one specifically for people who are new to Python).

Sample notebook of GLM in CAS using Python SWAT

Kevin and others have also been populating the sas-viya-programming project on GitHub. You'll find Python code samples, plus examples for accessing SAS Viya from other languages including SAS and R.

SAS trainers have recorded a tight 5-minute tutorial, "Getting Started with the Python Interface of SAS Viya". Be sure to check that out for a great overview of connecting to CAS and using several of the available actions.

And don't forget to check out the SAS Support Communities for SAS Viya coders. You can post questions and connect with the experts from SAS (and the rest of the world).

And finally, what if you don't have SAS Viya yet, but you're interested in using Python with SAS 9.4? Check out the SASPy project, which allows you to access your traditional SAS features from a Jupyter notebook or Python console. It's another popular open source project from SAS R&D.