BookmarkSubscribeRSS Feed

CASL: CAS Action Result Variables

Started ‎05-29-2020 by
Modified ‎05-29-2020 by
Views 4,137

In my last post, I compared CASL to Base SAS and SAS/MACRO, and provided examples of their similarities. The one big difference, however, was the mechanism used for referencing objects (tables, columns, librefs, directory paths, etc.) in generated code. With macro, we talked about using macro variable resolution. With CASL, we used CAS Action Result variables.

CAS Action Result Option ≈ SAS PROC Output Statement

CAS Action result variables are set using the CAS Action Result option.

 

casActionResultOption-300x96.png

CAS Action Result Option Example

Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.

 

The function of the CAS Action result option is much the same as the SAS Procedure Output statement. It directs the results of the CAS Action to a code-consumable object. In the case of the procedure output statement, the results go to a SAS table. In the case of the result option, the results go to a CASL Variable. In the example, the results are sent to the tabInf CASL variable.

CASL Variables

What are CASL variables? If you're a SAS programmer, you can think of them like MACRO variables without all of the resolution timing concerns. They also can take on numeric and other data types.

 

CASL has the usual SAS character and numeric data types but also allows for arrays, boolean, dictionaries, and tables. We'll focus on these last two here as CAS Action result variables are generally either dictionaries, tables, or some combination of the two.

CASL Describe Statement

So how do we know what's in our result variable? Is it a dictionary? A table? A dictionary with a table inside? If there's a table inside of a dictionary, what's the name of the table? Use the Describe statement.

 

casActionResultDescribe.png

CASL Describe Statement

 

Looking at the TableInfo example above, we see that the result variable is a dictionary that contains one entry, a table named "TableInfo."

CASL Dictionaries

Before we consider the table, let's look at the dictionary. A CASL dictionary is an array of key-value pairs. If you've coded some CASL, you'll probably recognize them. The tbl dictionary below contains two key-value pairs that define a CAS table.

 

tbl={name="iris", caslib="casuser"}

 

Our CASL dictionary, tabInf, contains only one key-value pair and looks something like this:

 

tabInf={TableInfo="<The table containing the information about the CAS tables in the DM Caslib>"}

 

 

To reference the members of CASL dictionaries, you use simple two-level naming, e.g. "tabInf.TableInfo."

CASL Table Variables

So what can we do with CASL Table variables? We can do quite a bit actually. We can subset them, add computed columns to them, and select values from them. We can also return their row counts, column counts, table names, and attributes. Typically we'll be accessing their values by row and column.

 

Let's access some values from our TblInf.TableInfo result table.

 

casActionResultTable.png

Printing Values from a CAS Action Result Table

 

The first print statement accesses the name of the first table in the DM CASlib. The second prints the encoding (the 6th column of the table) of the second table. The Do loop prints the names of all the tables in the CASlib.

 

For an example of spinning through a CAS Action Result table to load files into CAS, see my previous post. All of my posts on CASL are listed below:

Version history
Last update:
‎05-29-2020 11:53 AM
Updated by:
Contributors

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Labels
Article Tags