As with most things in programming, there are multiple ways of displaying help information about CAS action sets and actions from Python. We'll outline each of those methods in this article.
The first thing we need is a connection to CAS.
In[1]: import swat
In[2]: conn = swat.CAS(host, port, username, password)
help
Action
The CAS server has a builtin help system that will tell you about action sets and actions. To get help for all of the loaded action sets and a description of all of the actions in those action sets, you just call the help action with no parameters. In this case, we are storing the output of the action to a variable. That result contains the same information as the printed notes, but the information in encapsulated in DataFrame structures. Unless you are going to use the action set information programmatically, there isn't much reason to have it printed twice.
In[3]: out = conn.help()
NOTE: Available Action Sets and Actions:
NOTE: accessControl
NOTE: assumeRole - Assumes a role
NOTE: dropRole - Relinquishes a role
NOTE: showRolesIn - Shows the currently active role
NOTE: showRolesAllowed - Shows the roles that a user is a member of
NOTE: isInRole - Shows whether a role is assumed
NOTE: isAuthorized - Shows whether access is authorized
NOTE: isAuthorizedActions - Shows whether access is authorized to actions
NOTE: isAuthorizedTables - Shows whether access is authorized to tables
NOTE: isAuthorizedColumns - Shows whether access is authorized to columns
NOTE: listAllPrincipals - Lists all principals that have explicit access controls
NOTE: whatIsAuthorized - Lists the permissions that are effectively granted to the session's authenticated user
NOTE: whatIsEffective - Lists effective access and explanations (Origins)
... output truncated ...
If you only want to see the help for a single action set, you can specify the action set name as a parameter.
In[4]: out = conn.help(actionset='simple')
NOTE: Information for action set 'simple':
NOTE: simple
NOTE: mdSummary - Calculates multidimensional summaries of numeric variables
NOTE: numRows - Shows the number of rows in a Cloud Analytic Services table
NOTE: summary - Generates descriptive statistics of numeric variables such as the sample mean, sample variance, sample size, sum of squares, and so on
NOTE: correlation - Generates a matrix of Pearson product-moment correlation coefficients
NOTE: regression - Performs a linear regression up to 3rd-order polynomials
NOTE: crossTab - Performs one-way or two-way tabulations
NOTE: distinct - Computes the distinct number of values of the variables in the variable list
NOTE: topK - Returns the top-K and bottom-K distinct values of each variable included in the variable list based on a user-specified ranking order
NOTE: groupBy - Builds BY groups in terms of the variable value combinations given the variables in the variable list
NOTE: freq - Generates a frequency distribution for one or more variables
NOTE: paraCoord - Generates a parallel coordinates plot of the variables in the variable list
You can also specify a single action as a parameter. Calling the help action this way will also print descriptions of all of the action parameters.
In[5]: out = conn.help(action='summary')
NOTE: Information for action 'simple.summary':
NOTE: The following parameters are accepted. Default values are shown.
NOTE: list table={
NOTE: specifies the table name, caslib, and other common parameters.
NOTE: string name=NULL (required),
NOTE: specifies the name of the table to use.
NOTE: string caslib=NULL,
NOTE: specifies the caslib containing the table that you want to use with the action. By default, the active caslib is used. Specify a value only if you need to access a table from a different caslib.
NOTE: string where=NULL,
NOTE: specifies an expression for subsetting the input data.
NOTE: string list groupBy={
NOTE: specifies the names of the variables to use for grouping results.
NOTE: },
NOTE: specifies the names of the variables to use for grouping results.
NOTE: string list groupByFmts={
NOTE: specifies the format to apply to each group-by variable. To avoid specifying a format for a group-by variable, use "" (no format).
NOTE: },
NOTE: specifies the format to apply to each group-by variable. To avoid specifying a format for a group-by variable, use "" (no format).
... output clipped ...
help
Function
In addition to the help action, you can also use Python's help function. In this case, you have to specify an action set or action variable. In the code below, we will get the help for the simple action set. In addition to the actions in the action set, you will also get information about the action set's Python class.
In[6]: help(conn.simple)
Help on Simple in module swat.cas.actions object:
class Simple(CASActionSet)
| Analytics
|
| Actions
| -------
| simple.correlation : Generates a matrix of Pearson product-moment correlation coefficients
| simple.crosstab : Performs one-way or two-way tabulations
| simple.distinct : Computes the distinct number of values of the variables in the variable list
| simple.freq : Generates a frequency distribution for one or more variables
| simple.groupby : Builds BY groups in terms of the variable value combinations given the variables in the variable list
| simple.mdsummary : Calculates multidimensional summaries of numeric variables
| simple.numrows : Shows the number of rows in a Cloud Analytic Services table
| simple.paracoord : Generates a parallel coordinates plot of the variables in the variable list
| simple.regression : Performs a linear regression up to 3rd-order polynomials
| simple.summary : Generates descriptive statistics of numeric variables such as the sample mean, sample variance, sample size, sum of squares, and so on
| simple.topk : Returns the top-K and bottom-K distinct values of each variable included in the variable list based on a user-specified ranking order
|
| Method resolution order:
| Simple
| CASActionSet
| builtins.object
|
... output clipped ...
Alternatively, you can specify a particular action attribute. This will print information about the action parameters and the Python action class.
In[7]: help(conn.simple.summary)
Help on simple.Summary in module swat.cas.actions object:
class simple.Summary(CASAction)
| Generates descriptive statistics of numeric variables such as the sample mean, sample variance, sample size, sum of squares, and so on
|
| Parameters
| ----------
| table : dict or CASTable
| specifies the table name, caslib, and other common parameters.
|
| table.name : string or CASTable
| specifies the name of the table to use.
|
| table.caslib : string, optional
| specifies the caslib containing the table that you want to use
| with the action. By default, the active caslib is used.
| Specify a value only if you need to access a table from a
| different caslib.
|
| table.where : string, optional
| specifies an expression for subsetting the input data.
|
| table.groupby : list of strings, optional
| specifies the names of the variables to use for grouping
| results.
| Default: []
|
... output clipped ...
The IPython environment has a way of invoking help as well. It is more useful in the notebook environment where the help content will pop up in a separate pane of the browser. To bring up help for an action set, you simply add a ? after the action set attribute name.
In[8]: conn.simple?
Type: Simple
String form: <swat.cas.actions.Simple object at 0x7f0c92088b38>
File: actions.py
Signature: conn.simple(self, *args, **kwargs)
Docstring:
Analytics
Actions
-------
simple.correlation : Generates a matrix of Pearson product-moment correlation coefficients
simple.crosstab : Performs one-way or two-way tabulations
simple.distinct : Computes the distinct number of values of the variables in the variable list
simple.freq : Generates a frequency distribution for one or more variables
simple.groupby : Builds BY groups in terms of the variable value combinations given the variables in the variable list
simple.mdsummary : Calculates multidimensional summaries of numeric variables
simple.numrows : Shows the number of rows in a Cloud Analytic Services table
simple.paracoord : Generates a parallel coordinates plot of the variables in the variable list
simple.regression : Performs a linear regression up to 3rd-order polynomials
simple.summary : Generates descriptive statistics of numeric variables such as the sample mean, sample variance, sample size, sum of squares, and so on
simple.topk : Returns the top-K and bottom-K distinct values of each variable included in the variable list based on a user-specified ranking order
Call signature: conn.simple(*args, **kwargs)
The ? operator also works with action names.
In[9]: conn.simple.summary?
Type: simple.Summary
String form: ?.simple.Summary()
File: actions.py
Signature: conn.simple.summary(_self_, table=None, nthreads=None, groupbytable=None, groupbylimit=None, orderby=None, orderbyagg=None, orderbydesc=None, orderbygbyraw=None, multitable=None, limit=None, casout=None, repeat=None, freq=None, cialpha=None, citype=None, **kwargs)
Docstring:
Generates descriptive statistics of numeric variables such as the sample mean, sample variance, sample size, sum of squares, and so on
Parameters
----------
table : dict or CASTable
specifies the table name, caslib, and other common parameters.
table.name : string or CASTable
specifies the name of the table to use.
table.caslib : string, optional
specifies the caslib containing the table that you want to use
with the action. By default, the active caslib is used.
Specify a value only if you need to access a table from a
different caslib.
table.where : string, optional
specifies an expression for subsetting the input data.
... output clipped ...
Which one of the above described methods of getting help on CAS actions that you decide to use really depends on what type of information you are looking for and what environment you are in. If you are commonly working in IPython, the ? operator method is likely to be your best bet. If you simply want to see what actions are available in an action set, you may just call the help action directly. And if you are looking for information about the action as well as the Python action class methods, then Python's help function is what you are looking for.
You can download the Jupyter notebook of this article at https://github.com/sassoftware/sas-viya-programming/tree/master/communities.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.