Beyond Macros: Data-Driven Programming with CAS in SAS Viya
Simon 33 Aufrufe
Schwierigkeitsgrad
Confirmé
Veröffentlicht am :
Expertenrat
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.
Die auf WeAreCAS.eu bereitgestellten Codes und Beispiele dienen Lehrzwecken. Es ist zwingend erforderlich, sie nicht blind in Ihre Produktionsumgebungen zu kopieren. Der beste Ansatz besteht darin, die Logik zu verstehen, bevor sie angewendet wird. Wir empfehlen dringend, diese Skripte in einer Testumgebung (Sandbox/Dev) zu testen. WeAreCAS übernimmt keine Verantwortung für mögliche Auswirkungen oder Datenverluste auf Ihren Systemen.
SAS und alle anderen Produkt- oder Dienstleistungsnamen von SAS Institute Inc. sind eingetragene Marken oder Marken von SAS Institute Inc. in den USA und anderen Ländern. ® zeigt die Registrierung in den USA an. WeAreCAS ist eine unabhängige Community-Site und nicht mit SAS Institute Inc. verbunden.
Diese Website verwendet technische und analytische Cookies, um Ihre Erfahrung zu verbessern.
Mehr erfahren.