Beyond Macros: Data-Driven Programming with CAS in SAS Viya
Simon 33 vues
Niveau de difficulté
Confirmé
Publié le :
Le conseil de l'expert
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.
Les codes et exemples fournis sur WeAreCAS.eu sont à but pédagogique. Il est impératif de ne pas les copier-coller aveuglément sur vos environnements de production. La meilleure approche consiste à comprendre la logique avant de l'appliquer. Nous vous recommandons vivement de tester ces scripts dans un environnement de test (Sandbox/Dev). WeAreCAS décline toute responsabilité quant aux éventuels impacts ou pertes de données sur vos systèmes.
SAS et tous les autres noms de produits ou de services de SAS Institute Inc. sont des marques déposées ou des marques de commerce de SAS Institute Inc. aux États-Unis et dans d'autres pays. ® indique un enregistrement aux États-Unis. WeAreCAS est un site communautaire indépendant et n'est pas affilié à SAS Institute Inc.
Ce site utilise des cookies techniques et analytiques pour améliorer votre expérience.
En savoir plus.