Adopting SAS© Viya™ often comes with a performance goal: leveraging the in-memory CAS (Cloud Analytic Services) engine to accelerate data processing. For users accustomed to PROC SQL, this often involves migrating to PROC FedSQL.
However, although PROC SQL complies with the ANSI 92 standard, it also allows for many unique features specific to SAS©. PROC FedSQL, on the other hand, complies with the ANSI 99 standard and is optimized for distributed processing, but it does not handle some implicit SAS© syntax in the same way.
This article explores how to refactor classic PROC SQL conditional logic to work efficiently in a CAS environment with PROC FedSQL.
In classic SAS©, a common trick in PROC SQL is to sum the result of a boolean expression. SAS© evaluates a true condition as being equal to 1 and a false one as equal to 0.
Let's take this example using the sashelp.baseball table. We want to count the total number of items and calculate a sum based on a complex condition (where the absolute difference between hits and runs is less than 10% of at-bats).
Original PROC SQL Code:
When we switch to PROC FedSQL to run this code in a distributed manner on CAS, this implicit boolean-to-integer conversion is not supported in the same way by the stricter ANSI standard. If you try to run the code as-is, it will fail or not produce the expected result.
To emulate this behavior, we must make the logic explicit by using a CASE statement.
Refactored PROC FedSQL Code for CAS:
The goal when migrating to SAS© Viya™ is to use CAS to accelerate existing routines. Refactoring PROC SQL code into PROC FedSQL is an excellent way to achieve this, provided you master the syntactical nuances between the ANSI standards.
For PROC SQL code that proves too complex to refactor or uses SAS©-specific features not supported by FedSQL, it is still possible to run it as-is in the SAS© Programming Runtime Environment (SPRE) of Viya™.