The SWAT package includes the ability to call CAS actions and process the output in various ways. These range from simple (calling CAS actions as Python methods and getting a dictionary of results back) to complex (invoking CAS actions in multiple sessions and handling server responses from them directly). The various workflows are described in the following sections to give you an idea of how the classes in SWAT interact with each other.
The Easy Way¶
In the most basic form of calling CAS actions, the actions are called directly on the connection object or a CASTable object. When you load a CAS action set (using builtins.loadactionset), the CAS actions in that action set are added to the connection object as Python methods. For example, when the simple action set is loaded, the CAS connection object is extended with methods for summary, freq, crosstab, etc. These can then be called on the CAS connection object directly.
In addition, any CASTable objects that are registered with that connection also get methods for those actions. When you call a CAS action on a CASTable object, the table= (or name= and caslib= in some cases) parameter get populated automatically with that table object before it is sent to the CAS server.
Here is a simple example. We are reading a CSV file using the CAS.read_csv() method. This loads the CSV data into a CAS table and returns a CASTable object. You can then use many of the standard pandas.DataFrame methods such as pandas.DataFrame.head() to interact with the CAS table on the server.
In : import swat In : conn = swat.CAS(host, port, userid, password) In : tbl = conn.read_csv('https://raw.githubusercontent.com/' ...: 'sassoftware/sas-viya-programming/master/data/cars.csv') ...:
Note: Cloud Analytic Services made the uploaded file available as table TMPJEHQ5PCS in caslib CASUSER(castest).
Note: The table TMPJEHQ5PCS has been created in caslib CASUSER(castest) from binary data uploaded to Cloud Analytic Services. In : tbl.head()