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).
- 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.
9 Comments
Hello,
I am new to SAS Viya and we are planning to use it as a deployment tool in our company in the US. I wanted to know as an R and Python programmer, am I free to use whatever packages that I want when I am modeling with R and Python and then build the model and read it into SAS Viya for just the deployment or I am limited to use CAS package functions?
Mahsa,
I think the answer is Yes -- you can use SAS Model Manager to manage the lifecycle and deployment of your models, even if not built in SAS. See the SAS Model Manager learning center for more information. If you have follow-up questions, I suggest that you post to the SAS Data Mining and Machine Learning community.
I am running python on a windows machine. Will I be able to using any python to access SAS Viya? Is there a specific install required on the SAS server to enable this functionality?
Nothing special needed beyond the Python SWAT package and its dependencies. From Windows, you'll be using the HTTP protocol to access SAS Viya (binary protocol isn't yet supported). The GitHub project instructions should help, and you might read through the issue conversations that others have contributed.
Can we use other Python IDE like Pycharm , Apache Zeppelin, Rstudio, Rodeo IDE and Spark Notebook to use SWAT instead of jupyter notebok . What are challenges if we cant' use them ?
Yes, you should be able to use any Python environment as long as you have a proper version of Python (supported by SWAT). Here's a different blog post about RStudio.
Hi Chris,
Thanks for your reply .
1-We have many CAS actions and actions sets mentioned here -https://go.documentation.sas.com/?docsetId=allprodsactions&docsetTarget=actionSetsByName.htm&docsetVersion=3.3&locale=en
But when we do conn.help() then we able to see very few CAS actions and action set that we can use.
So it's under development for other cas actions or it is not planned or not feasible to call other actions using SWAT.
2-
when we do conn. then it shows all available cas actions along with some other methods which are not cas actions like read_csv which are based on python /pandas packages.
There are functions like concat which are under swat.functions which we can't call using conn. i.e. session object.
But there are object like swat.cas.table.CASTable which we can call using session object i.e. conn.CASTable().
Also we have 2 options i.e. swat.cas and swat.CAS and both have different methods , so what's difference in that?
So my questions is why is it so where few methods/functions we can call using session reference and some are not ? Is there a document where I can find the basics of it or the flow of the swat package ?
Hi Anant,
To answer your first question, the SWAT package has a handful of action sets at install. You can see the action sets by running swat.help().
Here are some helpful commands for displaying action sets and actions:
Put the available action sets in a variable:
out = conn.help
Give me a list of action sets- returns results in a dictionary:
list(out.keys())
List the action sets in table form:
out
List a specific action set:
out['bullitens']
If you want to use actions from other action sets, you import them first:
conn.loadactionset('aggregation')
Now you can use any actions in the aggregation action set. Here is a link to all actions and action sets.
The SWAT documentation is found at this link. You may want to refer to the API reference section for more info on swat.CAS. Another good place to start would be on the developer.sas.com's page on Python.
Pingback: Should you be banking on open source analytics? - Hidden Insights