CASL is a language specification that can be used by the SAS client to interact with and provide easy access to Cloud Analytic Services (CAS). CASL is a statement-based scripting language with many uses and strengths including:
- Specifying CAS actions to submit requests to the CAS server to perform work and return results.
- Evaluating and manipulating the results returned by an action.
- Creating user-defined actions and functions and creating the arguments to an action.
- Developing analytic pipelines.
CASL uses PROC CAS which enables you to program and execute CAS actions from the SAS client and use the results to prepare the parameters for a subsequent action. A single PROC CAS statement can contain several CASL programs. With the CAS procedure you can run any CAS action supported by the server, load new action sets into the server, use multiple sessions to perform asynchronous execution and operate on parameters and results as variables using the function expression parser.
CASL, and the CAS actions, provide the most control, flexibility and options when interacting with CAS. One can use DATA Step, CAS-enabled PROCS and CASL for optimal flexibility and control. CASL works well with traditional SAS interfaces and the Base SAS language.
Each CAS action belongs to an action set. Each action set is further categorized by product (i.e. VA, VS, VDMML, etc.). In addition to the many CAS actions supplied by SAS, as of SAS® Viya™ 3.4, you can create your own actions using CASL. Developing and utilizing your own CAS actions allows you to further customize your code and increase your ability to work with CAS in a manner that best suits you and your organization.
About user-defined action sets
Developing a CASL program that is stored on the CAS server for processing is defined as a user-defined action set. Since the action set is stored on the CAS server, the CASL statements can be written once and executed by many users. This can reduce the need to exchange files between users that store common code. Note that you cannot add, remove, or modify a single user-defined action. You must redefine the entire action set.
Before creating any user-defined actions, test your routines and functions first to ensure they execute successfully in CAS when submitted from the programming client. To create user-defined actions, use the defineActionSet action in the builtins action set and add your code. You also need to modify your code to use CASL functions such as SEND_RESPONSE, so the resulting objects on the server are returned to the client.
Developing new actions by combining SAS-provided CAS actions
One method for creating user-defined CAS actions is to combine one or more SAS provided CAS actions into a user-defined CAS action. This allows you to execute just one PROC CAS statement and call all user-defined CAS actions. This is beneficial if you repeatedly run many of the same actions against a CAS table. An example of this is shown below. If you would like copy of the actual code, feel free to leave a reply below.
In this example, four user-defined CAS actions named listTableInfo, simplefreq, detailfreq, and corr have been created by using the corresponding SAS-provided CAS actions tableInfo, freq, freqTab, and correlation. These four actions return information about a CAS table, simple frequency information, detailed frequency and tabulate information, and Pearson correlation coefficients respectively. These four actions are now part of the newly created user-defined action set myActionSet. When this code is executed, the log will display a note that the new action set has been added.
Once the new action set and actions have been created, you can call all four or any combination of them via a PROC CAS statement. Specify the user-defined action set, user-defined action(s), and parameters for each.
Developing new actions by writing your own code
Another way to create user-defined CAS actions is to apply user-defined code, functions, and statements instead of SAS-provided CAS actions.
In this example, two user-defined CAS actions have been created, bdayPct and sos. These actions belong to the new user-defined action set myFunctionSet.
To call one or both actions, specify the user-defined action set, user-defined action(s), and parameters for each.
The results for each action are shown in the log.
Save and load custom actions across CAS sessions
User-defined action sets only exist in the current CAS session. If the current CAS session is terminated, the program to create the user-defined action set must be executed again unless an in-memory table is created from the action set and the in-memory table is subsequently persisted to a SASHDAT file. Note: SASHDAT files can only be saved to path-based caslibs such as Path, DNFS, HDFS, etc. To create an in-memory table and persist it to a SASHDAT file, use the actionSetToTable and save CAS actions.
To use the user-defined action set, it needs to be restored from the saved SASHDAT file. This is done with the actionSetFromTable action.
More about CASL programming and CAS actions
Check out these resources for further information on programming in the CASL language and running actions with CASL.
- Documentation: SAS® Cloud Analytic Services 3.4: CASL Programmer’s Guide
- SAS Global Forum paper: Management and Usage of User-Defined Formats in the SAS® Cloud Analytic Services Server
- Tech Talk Video: SAS programming in the cloud: CASL code
This really helps could you please share the copy of actual code for reference.