BookmarkSubscribeRSS Feed

Getting Started on SAS Viya 4 with Python

Started ‎07-26-2022 by
Modified ‎07-26-2022 by
Views 8,067

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.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 

  • SWAT (Scripting Wrapper for Analytics Transfer) provides an interface to the SAS Cloud Analytic Service (CAS) 
  • Don't forget to run a pip install swat command on your first attempt

 

Next, we will need to generate an authentication code to be used in downstream processes. 

  • Simply generate a code and copy/paste into your Notebook. 
  • Long-time SAS users may notice this example demonstrates a relatively new approach to Authentication for SAS Viya 4. 

https://myviya4instance.com/SASLogon/oauth/authorize?client_id=SWAT&response_type=code

 

Example of an Authentication Code - easily copy/paste into your NotebookExample 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 SWATA boilerplate connection string for SWAT

 

 

 

Next, we will load an Action Set

 

Blog_Notebook_CAS_ActionSet.png

 

Now that we have established a connection and loaded our Action Set, let's interact with a dataset 

Blog_Notebook_CAS_Data_Load.png

 

From here, you are off to the races! A minimalist example is below. 

Basic Example of SWATBasic 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!  

Contributors
Version history
Last update:
‎07-26-2022 03:16 PM
Updated by:

SAS AI and Machine Learning Courses

The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.

Get started

Article Tags