Are you just getting started with SAS Viya 4 and looking to build models?
As someone new to the world of SAS, running python code outside of Model Studio helped me gain a better understanding of the underlying SAS architecture.
In this article we are running the notebook within Azure Machine Learning Workspace and are connected to a typical SAS Viya 4 instance. Check out this GitHub page for the Notebook used in this example.
Connect to SAS Viya 4 with Azure Machine Learning Workspace Notebooks. You can also leverage this same code in your own local environment with Jupyter.
The first step is to import the official SAS Viya 4 Python Library: SWAT
Next, we will need to generate an authentication code to be used in downstream processes.
https://myviya4instance.com/SASLogon/oauth/authorize?client_id=SWAT&response_type=code
Example of an Authentication Code - easily copy/paste into your Notebook
After you authenticate, we are ready to create a connection to SAS Viya 4
A boilerplate connection string for SWAT
Next, we will load an Action Set
Now that we have established a connection and loaded our Action Set, let's interact with a dataset
From here, you are off to the races! A minimalist example is below.
Basic Example of SWAT
Congrats - you have successfully run a python version of a SAS Viya 4 model!
Check out the official SWAT API Reference for additional details and examples.
Do you have feedback or are looking for more examples? Get in touch with us by commenting below!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.