BookmarkSubscribeRSS Feed

Writing Custom SAS® Studio Tasks That Use CAS Actions for Advanced Analytics

Started ‎06-08-2020 by
Modified ‎06-08-2020 by
Views 2,829

Imagine that you want to develop SAS® code to build an analytical model in order to answer a business or research question of interest. This request is intentionally vague because it can be any model that you want to use, and the question of interest can be anything relevant to your domain or industry. 

 

In addition, suppose you specifically want to develop the code by using the relatively new SAS® Cloud Analytic Services (CAS) language, or CASL for short, which is a scripting language available with SAS® Viya®. It could be that you want the additional flexibility or the access to more advanced options available with CASL. Or it could be that you have a collaborator who accesses CAS from an open source language such as R or Python, and you want to use CASL because its syntax is similar to the code you use to interact with CAS from those languages.   

 

You could develop this code from scratch. But often it is more efficient to rely on existing code, such as examples from SAS documentation, blog posts, GitHub repositories, SAS® Global Forum papers, or previous code that you or a colleague wrote. 

 

What if I told you that there is an even more efficient way to develop your code? What if I told you that you do not need to actually write the code, but instead you can use a graphical user interface that automatically generates the code for you? 

 

SAS® Studio tasks do just that: they enable you to prepare and analyze your data without the need to write code (Figure 1).

 

Figure 1 Hidden Markov Models Task CASL Code Generation

taskCodeGenCAS.PNG

Not only do tasks make SAS analytics accessible to noncoders, but the real-time code generation can also help you learn the syntax for the method of interest. This is especially useful as you migrate your analytics to SAS Viya and learn the syntax for CAS actions and CAS-enabled procedures. 

 

In addition, even experienced SAS programmers can use these tasks to accelerate new code development. With just a few clicks and keystrokes, you can have several lines of formatted, typo-free CASL code that is not missing any commas or semicolons!

 

You can also customize the tasks to suit your needs. For example, if you or your colleagues routinely use a particular set of SAS procedures or CAS actions with different data sets and slightly different options, you can create and share a custom task to easily do exactly that.

 

Developing custom SAS Studio tasks that generate CASL code is the topic of my SAS Global Forum 2020 paper, “Tips for Writing Custom SAS Studio Tasks That Use CAS Actions for Advanced Analytics.” 

 

The paper uses analytical actions in SAS® Econometrics software to walk you through the process of adding new functionality to the existing Hidden Markov Models task. Although it is possible to write custom tasks from scratch, you can create a copy of a predefined SAS task and then modify it. This is a great way to dip your toe into the custom-task-writing water. 

 

To follow along with the paper, you need access to a CAS server that has a license for SAS Econometrics software. For more information about free software trials of SAS Viya, visit the SAS Trials website. Additional code that you need in order to finish Example 2 in the paper, along with the complete task code for both examples, is available in the SAS Global Forum 2020 GitHub repository.

 

Your comments and questions are valued and encouraged. Please post them to this article. 

 

Recommended Resources

The following references are great resources for custom task writing:

 

Comments

All the Viya tasks produce CASL code, or just some of them?  Great way to learn the syntax!

Hi @logbaseten,

 

Most, but not all, of the SAS Viya tasks have an option to generate code by using either a CAS-enabled procedure or the CAS procedure and CASL. 

 

The following is a list of tasks that do have this option.  The list is as of SAS Studio 5.2 (Viya 3.5), which was released at the end of last year.  Category names are in bold and task names are in regular font.  

 

SAS Viya Statistics

Decision Tree

 

SAS Viya Machine Learning 

Semi-supervised Learning

Semi-supervised Learning

Unsupervised Learning

Fast k-Nearest Neighbor
Market Basket Analysis

Supervised Learning

Neural Network
Support Vector Machine

 

SAS Viya Econometrics

Cross-sectional Data Models

Panel Data Models

Severity Models

Aggregate Loss Models

Spatial Regression Models

Hidden Markov Models

 

SAS Viya Forecasting

Time Series Modeling

Time Series Data Preparation

Time Series Exploration

Modeling and Forecasting

Time Series Mining

Motif Discovery

Motif Scoring

Subsequence Anomaly Detection

Similarity Analysis

 

SAS Viya Optimization and Network Analysis

Biconnected Components

Centrality Metrics

Community Detection

Connected Components

Core Decomposition

Cycle Detection

Linear Assignment

Maximal Cliques

Minimum Cost Network Flow

Minimum Cut

Minimum Spanning Tree

Reach Network

Shortest Paths

Summary Statistics

Transitive Closure

Traveling Salesman Problem

 

In addition, the following tasks generate only CASL code:

 

SAS Viya Cloud Analytic Services

CAS Operations

SAS Viya Machine Learning

Automated Machine Learning

Automated Feature Engineering

Computer Vision

Load Images

SAS Viya Text Analytics

Text Summarization

Segmentation

 

Lastly, there are two tasks that generate PROC code or CASL code depending on the options that you select.  Specifically, if you use the LDA topic model, the task generates CASL code, but otherwise it generates PROC code.

 

SAS Viya Text Analytics

Text Parsing and Topic Discovery

Text Scoring

 

I hope this information is helpful.  Please let me know if you have any additional questions or feedback on the tasks.

 

Thanks,

 

-Brian

 

 

Rad, thanks for the info and thorough response!  I dont wanna sound unappreciative, but I saw that most of the stats and ML tasks don't have the CASL option.  There a reason for that, and there a chance that will be added?  Those are what I usually use. 

Hi @logbaseten,

 

No problem!  I'm glad to help. 

 

I think the main reason that only a few tasks in the SAS Viya Statistics or SAS Viya Machine Learning categories have an option to generate CASL code is due to a focus on other priorities as determined by product management.  I am not aware of plans for that option to be added to those tasks but it's great to know that you would find it useful and I will pass this info along to product management.

 

Out of curiosity, for those tasks/methods, what are the main reasons why you prefer to use CASL code instead of PROC code?

 

Thanks,

 

-Brian

Version history
Last update:
‎06-08-2020 08:29 AM
Updated by:
Contributors

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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 Tags