Beyond Macros: Data-Driven Programming with CAS in SAS Viya
Simon 33 views
Difficulty Level
Confirmé
Published on :
Expert Advice
Michael
The most common performance killer in SAS Viya is treating the CAS server as a simple storage disk by using traditional Macro loops to send thousands of tiny snippets of code. To truly unlock the power of Viya, shift your logic into CASL (CAS Language): by using Result Tables and DO OVER loops, you execute the entire control logic directly in-memory, reducing network overhead and architectural latency.
This article demystifies these interactions and explores how to use CASL variables for dynamic, data-driven programming, which is often more efficient than traditional macros.
1. Understanding the Architecture: Where Does Your Code Run?
2. CASL Variables: More Powerful Than Macro Variables
Unlike macro variables, which are just text, CASL uses dynamically typed variables (the type is defined upon assignment)5. The true power of CASL lies in its composite data types.
The modern and high-performance equivalent of macro loops (%DO %WHILE or loops on call execute) is the DO OVER loop in CASL. It allows for easy iteration over arrays, dictionaries, or result tables.
DO OVER Loop Syntax
For a Dictionary:DO , OVER ;
For an Array:DO OVER ;
For a Table: You iterate over the rows as if it were an array.
Table 3: Macro vs. CASL Comparison for Data-Driven Programming
Example of UDF logic:You can create a loadAllFiles(caslib) function that retrieves the list of files from a caslib and loops over them to automatically load them into memory, thus replacing dozens of lines of complex macro code.
The codes and examples provided on WeAreCAS.eu are for educational purposes. It is imperative not to blindly copy-paste them into your production environments. The best approach is to understand the logic before applying it. We strongly recommend testing these scripts in a test environment (Sandbox/Dev). WeAreCAS accepts no responsibility for any impact or data loss on your systems.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.