Frequently Used Python SWAT Classes for CAS in SAS Viya

The SAS Viya SWAT (SAS Scripting Wrapper for Analytics Transfer) package provides Python classes for interacting with CAS (Cloud Analytic Services). The most frequently used classes are CASResults, which contains the output of CAS actions, and CASTable, which represents an in-memory table on the CAS server.

CASResults

To introduce the classes that are part of SWAT, put the results of the serverStatus action in a variable and display the type:

Results of the serverStatus action.

As shown, the class is CASResults. The class is a subclass of Python's dictionary. One aspect of the serverStatus action is that the results include a table that is named Server. That table shows the number of actions that were run. The following figure shows how you can access that table from the result and display it:

Using the display function to show parts of the serverStatus action results.

This is an introduction to the CASResults class. There are more examples that demonstrate how to work with results in this document.

CASTable

The CASTable class represents an in-memory table in SAS Cloud Analytic Services.

A simple way to work with a CASTable is to use the upload_file method that can download a file from a website, transfer it to the server, and then import it.

The upload_file method uses Python to download data and then transfers it to the server.
TipAn instance of the CASTable class represents an in-memory table in the server. An instance of the class does not contain the actual data from the table. In the preceding example, Titanic3 is not a DataFrame in Python that includes rows and columns of data. Titanic3 is a variable that represents an in-memory table. The in-memory table on the server includes the rows and columns of data.

CASTable objects can accept the name of an action, such as table.columnInfo. Your session can then run the action on the table.

Partial results for the table.columnInfo action.

Because the purpose of the server is to analyze data, the CASTable class is designed to provide a syntactic shortcut for running actions. The following two programming snippets are functionally equivalent.

Using a CASTable Object to Run an Action

titanic3.table.columnInfo()

Running an Action and Specifying the Table Parameter

s.table.columnInfo(table="titanic3")

You can use a CASTable object to run an action and then save the result in a CASResults instance.

Partial results for the simple.summary action.

In the preceding example, the SummaryResults variable is a CASResults object. In many cases, an action produces many tabular results in the CASResults object. These tabular results are SASDataFrame objects. They are a subclass of Pandas DataFrame with SAS metadata such as labels, titles, and columns. Otherwise, they are equivalent.

Within a CASResults object, tabular data is a SASDataFrame.

Additional Classes

See the API reference for the SWAT package to learn more about the CASResults class, the CASTable class, and additional classes.

https://sassoftware.github.io/python-swat/api.html

Last updated: October 12, 2026