The SAS Scripting Wrapper for Analytics Transfer (SWAT) package is the Python client to SAS Cloud Analytic Services (CAS). It allows users to execute CAS actions and process the results all from Python.

sassoftware, updated 🕥 2023-03-21 17:33:21

SAS Scripting Wrapper for Analytics Transfer (SWAT)


The SAS SWAT package is a Python interface to the SAS Cloud Analytic Services (CAS) engine (the centerpiece of the SAS Viya framework). With this package, you can load and analyze data sets of any size on your desktop or in the cloud. Since CAS can be used on a local desktop or in a hosted cloud environment, you can analyze extremely large data sets using as much processing power as you need, while still retaining the ease-of-use of Python on the client side.

Using SWAT, you can execute workflows of CAS analytic actions, then pull down the summarized data to further process on the client side in Python, or to merge with data from other sources using familiar Pandas data structures. In fact, the SWAT package mimics much of the API of the Pandas package so that using CAS should feel familiar to current Pandas users.

With the best-of-breed SAS analytics in the cloud and the use of Python and its large collection of open source packages, the SWAT package gives you access to the best of both worlds.

To view updates to this project see the Change Log.


To access the CAS binary protocol (recommended), you need the following:

  • 64-bit Python 2.7.x or 3.5+ on Windows or Linux (see shared library notes below)

The binary protocol requires pre-compiled components found in the pip installer only. These pieces are not available as source code and are under a separate license (see documentation on SAS TK). The binary protocol offers better performance than REST, especially when transferring larger amounts of data. It also offers more advanced data loading from the client and data formatting features.

To access the CAS REST interface only, you can use the pure Python code which runs in Python 2.7/3.5+ on all platforms. While not as fast as the binary protocol, the pure Python interface is more portable.

Linux Library Dependencies

Some Linux distributions may not install all of the needed shared libraries by default. Most notably, the shared library is required to make binary protocol connections to CAS. If you do not have this library on your machine you can install the numactl package for your distribution to make it available to SWAT.

Python Dependencies

The SWAT package uses many features of the Pandas Python package and other dependencies of Pandas. If you do not already have version 0.16.0 or greater of Pandas installed, pip will install or update it for you when you install SWAT.


SWAT can be installed using pip or conda (if you are using Anaconda)::

pip install swat

conda install -c sas-institute swat

You can also install from the files on the SWAT project releases page. Simply locate the file for your platform and install it using pip as follows:

pip install

Where X.X.X is the release you want to install, and platform is the platform you are installing on. You can also use the source code distribution if you only want to use the CAS REST interface. It does not contain support for the binary protocol.

Getting Started

For the full documentation go to A simple example is shown below.

Once you have SWAT installed and you have a CAS server to connect to, you can import swat and create a connection::

>>> import swat
>>> conn = swat.CAS(host, port, username, password)

Note the default port for the Python SWAT connection is 5570.

If you are using python-swat version 1.8.0 or later to connect to a SAS Viya 3.5 CAS server using Kerberos, prior to connecting you must set the Service Principal Name (SPN) using the CASSPN environment variable. For SAS Viya 3.5, the SPN string must start with '[email protected]', followed by the hostname.

export [email protected]

If you get an error message about the TCP/IP negClientSSL support routine, you likely have an issue with your SSL certificate configuration. See the Encryption documentation for more information.

If that is successful, you should be able to run an action on the CAS server::

>>> out = conn.serverstatus()
NOTE: Grid node action status report: 1 nodes, 6 total actions executed.
>>> print(out)

 {'CAS': 'Cloud Analytic Services',
  'Copyright': 'Copyright © 2014-2016 SAS Institute Inc. All Rights Reserved.',
  'System': {'Hostname': 'cas01',
   'Model Number': 'x86_64',
   'OS Family': 'LIN X64',
   'OS Name': 'Linux',
   'OS Release': '2.6.32-504.12.2.el6.x86_64',
   'OS Version': '#1 SMP Sun Feb 1 12:14:02 EST 2015'},
  'Version': '3.01',
  'VersionLong': 'V.03.01M0D08232016',
  'license': {'expires': '20Oct2016:00:00:00',
   'gracePeriod': 62,
   'site': 'SAS Institute Inc.',
   'siteNum': 1,
   'warningPeriod': 31}}


 Server Status

    nodes  actions
 0      1        6


 Node Status

     name        role  uptime  running  stalled
 0  cas01  controller   4.836        0        0

+ Elapsed: 0.0168s, user: 0.016s, sys: 0.001s, mem: 0.287mb

>>> conn.close()


The Contributor Agreement details on how contributions can be made to the project. The Contributing includes instructions and rules as it relates to making contributions on the project.


The states how this package is released and licensed.

Additional Resources


pip3 deprecation warning for coming pip23.1 when installing swat

opened on 2023-03-17 22:05:02 by dstonehouse

I got this warning when I installed swat today: DEPRECATION: swat is being installed using the legacy ' install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at

I resolved this by installing the wheel package. It seems one of two things is needed: a) update the doc to mention the wheel package as a dependency or b) make the swat install compatible with the coming pip 23.1 release

Failed to access file /cascache/cascache/

opened on 2023-03-02 08:50:01 by FK7

Hi Team,

I attempted to utilize the swat package to push a pandas dataframe as a Sas table to a Sas server, but I encountered an error message that states "Failed to access cache file." Below is the code that I am executing for your reference. I would highly appreciate your assistance.


Verify file existence at a designated path

python if not os.path.exists(castable_path): raise ValueError("Unable to locate CASTable at the specified path.")

Transfer CASTable to SAS server

python try: conn.loadactionset("table") conn.upload(castable_path, casout=dict(name="mytable_1", replace=True, caslib='CASUSER(sasboot)')) print("CASTable successfully uploaded!") except swat.CASActionError as e: print(f"An error occurred while uploading CASTable: {e}")

Please note that I received the following output while running the code:

NOTE: Added action set 'table'. CASTable uploaded successfully!

ERROR: Failed to access file /cascache/cascache/_f_1e7ad78a_7f7b9bcc1b68.sashdat. ERROR: The action stopped due to errors.


opened on 2023-01-19 08:46:01 by Blake3562 None

applying formats using fetch or to_frame makes all DataFrame columns objects

opened on 2022-12-22 13:50:05 by pestyld

If you have formats on only a few columns in a CAS table and try to apply the formats to the SASDataFrame, the swat package converts all columns to objects, even if the column is a simple number.

For example:


import swat import pandas as pd

Connect to CAS

conn = ##connection info

load data to CAS

data = r'' tbl = conn.upload_file(data, casout = {'name':'cars_upload', 'caslib':'casuser','replace':True}, importoptions={ 'stripBlanks':True, 'guessRows':200, 'vars':{ 'MSRP':{'format':'dollar16.'}, 'Weight':{'format':'comma16.'} }})

Only the MSRP and Weight columns have a format



Pull the CAS table to the client as a SASDataFrame and apply the formats. This works as expected

df = tbl.to_frame(format=True) df.head()


View the data types of the SASDataFrame


Everything turns into an object. It seems like only the formatted columns should be converted. Numeric columns without formats should remain numbers.

read_sas() but no to_sas() ?

opened on 2022-11-29 10:08:00 by deboomce

Why is there a read_sas() method but no to_sas() method?

Merge method on CASTable ignores 'name' in casout

opened on 2022-11-29 09:59:50 by deboomce

When merging two CASTable objects, the output CASTable gets a generated name rather than the name that is specified in the casout options.


SWAT v1.12.2-snapshot 2023-03-21 16:28:19

(Development snapshot)

SWAT v1.12.1 2023-01-09 13:25:28

Highlights include:

  • Update Authentication documentation

To install the SWAT v1.12.1 package, use the pip command as follows:: pip install swat

Or, if you are using Anaconda:: conda install -c sas-institute swat

SWAT v1.12.0 2022-11-11 14:04:26

Highlights include:

  • New Image CASDataMsgHandler to allow easy uploading of client-side images to a CAS table
  • Update TK subsystem

To install the SWAT v1.12.0 package, use the pip command as follows:: pip install swat

Or, if you are using Anaconda:: conda install -c sas-institute swat

SWAT v1.11.1-snapshot 2022-08-16 13:37:10

(Development snapshot)

SWAT v1.11.0 2022-07-05 16:10:50

Highlights include:

  • Update TK subsystem

To install the SWAT v1.11.0 package, use the pip command as follows:: pip install swat

Or, if you are using Anaconda:: conda install -c sas-institute swat

SWAT v1.10.0 2022-06-10 13:33:40

Highlights include:

  • Add Python 3.10 support
  • Update TK subsystem

To install the SWAT v1.10.0 package, use the pip command as follows:: pip install swat

Or, if you are using Anaconda:: conda install -c sas-institute swat

SAS Software

Open Source from SAS Software

GitHub Repository

sas python sas-swat