The SAS Risk Engine on SAS Viya stands as a powerful, scalable platform engineered to deliver modern risk analytics tailored for the complex needs of financial institutions. As an integral part of SAS’s comprehensive risk management suite, it harnesses the agility of Viya’s cloud-native architecture. Among its many capabilities, the SAS Risk Engine allows users to extend its functionality by incorporating custom functions, enabling organizations to align risk analytics precisely with their unique business requirements.
This article offers the developers, administrators and implementers a guided overview of the process involved in creating and integrating a custom SAS function within the SAS Risk Engine. It is intended for readers with a foundational understanding of SAS programming, SAS functions and a working familiarity with the SAS Risk Engine environment.
You can obtain more information on SAS Risk Engine using the following links.
Using the SAS Risk Engine Interface
|
SAS Functions in SAS Risk Engine
In the SAS Risk Engine, functions play a critical role in supporting pricing methodologies and enabling the creation of user-defined statistics. These functions are organized into function sets, which can be invoked within risk methods and model groups to extend analytical capabilities. Included with the SAS Risk Engine is a built-in function set named RE_BASE_FUNCTIONS. This core library offers essential tools such as random number generators, piecewise-linear interpolation utilities, and functions for computing both the cumulative distribution function (CDF) and its inverse.
However, there may be situations where the out-of-the-box functions provided by SAS do not fully meet your analytical needs. In such cases, you can develop custom functions, much like those created using PROC FCMP. Within a function block, you have the flexibility to embed the necessary logic—using SAS statements and other callable functions—to compute and return the desired result.
Note that SAS Risk Engine supports python and C based functions as well. For more information refer to Help Center documentation using the following link:
SAS Risk Engine Help Documentation
Here is a simple example of a custom SAS function along with the general syntax.
Illustration of a simple custom SAS function.
Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.
At a minimum, a custom function must define the following required arguments:
In addition to these core components, optional arguments can also be specified to enhance the function’s flexibility or tailor its behaviour to specific use cases.
For a comprehensive list and details on using optional arguments, please refer to the Help Center documentation.
Primarily there are five steps:
Illustration of steps for adding a custom function
You may add your custom function code directly to SAS Risk Engine. However, is always suggested to write your custom function code in SAS Studio. Test it for the logic and syntax before you add it to SAS Risk Engine. You may choose to use PROC FCMP or PROC COMPILE. Here is an example of a simple function in SAS Studio editor along with a sample code to test the function.
Illustration of a SAS Program for a Custom Function in SAS Studio
In the example above, we define a custom function called simple_interest using PROC FCMP in SAS. This function calculates simple interest based on the formula (Principal × Rate × Time) / 100 and is stored in a custom function library. We then test the function by calling it in a DATA step, passing sample values for principal, rate, and time. The result is stored in a new variable and printed using PROC PRINT, verifying that the function returns the correct interest amount.
This step is easy. It enables you to create a placeholder for your custom function or functions within the SAS Risk Engine. It not only helps you to store your function code, but it also helps the solution to recognize and make the function available to your environment wherever necessary.
To create a new function set, navigate to the Function Sets page and
Illustration of New Function Set Window.
Add your code to the function set. You can use the original code created in SAS Studio. You need to include only the function statement. PROC FCMP and Quit statements are not required here.
In the following example, The OtherRetailRW or RevolvingRetailRW function calculates the capital requirement (risk weight) for retail credit exposures under the Basel II framework using Probability of Default (PD) and Loss Given Default (LGD) as inputs. It applies PD flooring and capping, computes a correlation factor (R), and uses the Vasicek model to estimate unexpected loss (K). The business purpose is to determine regulatory capital that banks must hold against credit risk, ensuring compliance and effective risk management for retail portfolios. Note that there are other similar functions included in the code not shown in the screenshot below.
Illustration of Adding Code to a Function Set.
In this step, you incorporate the function into your method code, which serves as the core logic for risk analytics. SAS solutions that leverage the SAS Risk Engine—such as SAS Stress Testing, SAS Allowance for Credit Loss, and others—commonly utilize these functions within risk methods or method codes defined in model groups for a specific project. Additionally, you can embed these functions in custom code tailored to the unique requirements of your project.
Here is an example of custom risk weighted custom functions being used in SAS Stress Testing solution.
Illustration of Using a Custom Function in a Method Code.
Testing can be performed by running a specific task within any standard or custom cycle that includes the method code, allowing you to validate the function’s behavior within a complete risk workflow. The SAS Risk Engine automatically generates execution logs for any method code it runs, which can be accessed from the main pipeline page.
Illustration of a Successfully Executed Pipeline.
Additionally, each SAS solution presents these logs in text format and provides results in various formats, such as raw CAS tables or both standard and custom reports in SAS Visual Analytics. As a user, you can review the execution logs to identify any runtime errors and examine the output tables and reports to detect potential logical issues in the custom function.
In conclusion, the SAS Risk Engine on SAS Viya distinguishes itself with the powerful ability to integrate custom functions, offering organizations the flexibility to tailor risk analytics around their unique business requirements. This article has walked through the process of creating and embedding a custom SAS function within the SAS Risk Engine, serving as a practical companion for developers and solution implementors working across diverse SAS solutions within financial institutions. It is this blend of adaptability and precision that makes the Risk Engine not just a tool, but a strategic asset in the evolving landscape of risk management.
Find more articles from SAS Global Enablement and Learning here.
The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.