The addRoutines action adds FCMP (Function Compiler) routines and stores them in a CAS table. This allows for the creation and management of user-defined functions and subroutines that can be used in various SAS Viya procedures and DATA steps running in CAS. It is a key component for extending SAS functionality with custom logic.
| Parameter | Description |
|---|---|
| appendTable | When set to TRUE, this option appends the new functions to an existing FCMP table. If FALSE, it overwrites the table. The default is FALSE. |
| funcTable | Specifies the output CAS table where the compiled FCMP functions and subroutines will be stored. This table can then be used by other CAS actions or procedures. |
| library | Specifies an existing FCMP library to load. This is useful for referencing functions or subroutines that are already compiled and stored. |
| package | Defines the name of the FCMP package where the functions and subroutines will be stored. Packages help in organizing and avoiding name conflicts. |
| routineCode | A list of strings containing the source code for the FCMP functions or subroutines to be compiled and added to the table. This is the core parameter where you provide your custom logic. |
| saveTable | When set to TRUE, it specifies that the in-memory table containing the FCMP functions should be saved as a physical file in the caslib. The default is FALSE. |
This action does not directly use input data, but it creates a CAS table containing the compiled functions. The following examples will demonstrate how to create and use these function tables.
| 1 | /* No |
| 2 | data creation is needed for this action, as it generates a function table from code. */ |
This example compiles a simple function named 'myadd' that adds two numbers and stores it in a CAS table named 'myfuncs'.
| 1 | PROC CAS; |
| 2 | fcmpact.addRoutines |
| 3 | routineCode={"function myadd(a, b); return(a+b); endsub;"}, |
| 4 | package="mypackage", |
| 5 | funcTable={name="myfuncs", caslib="casuser", replace=true}; |
| 6 | RUN; |
This example demonstrates compiling multiple functions ('myadd' and 'mymultiply') in a single call. It also shows how to use the 'saveTable' option to persist the function table to disk for future sessions.
| 1 | PROC CAS; |
| 2 | fcmpact.addRoutines |
| 3 | routineCode={ |
| 4 | "function myadd(a, b); return(a+b); endsub;", |
| 5 | "function mymultiply(a, b); return(a*b); endsub;" |
| 6 | }, |
| 7 | package="mymathpackage", |
| 8 | funcTable={name="mymathfuncs", caslib="casuser", replace=true}, |
| 9 | saveTable=true; |
| 10 | RUN; |
This example first creates a table with one function, and then uses the 'appendTable' option to add a second function to the same table without overwriting the original one.
| 1 | PROC CAS; |
| 2 | /* Step 1: Create the initial table with one function */ |
| 3 | fcmpact.addRoutines |
| 4 | routineCode={"function myadd(a, b); return(a+b); endsub;"}, |
| 5 | package="myaggpackage", |
| 6 | funcTable={name="myaggfuncs", caslib="casuser", replace=true}; |
| 7 | |
| 8 | /* Step 2: Append a new function to the existing table */ |
| 9 | fcmpact.addRoutines |
| 10 | routineCode={"function mysubtract(a, b); return(a-b); endsub;"}, |
| 11 | package="myaggpackage", |
| 12 | funcTable={name="myaggfuncs", caslib="casuser"}, |
| 13 | appendTable=true; |
| 14 | RUN; |
A retail company needs to deploy a custom function to calculate tiered discounts for customers based on their loyalty status and purchase amount. This function must be made avai...
A financial institution is building a centralized library of risk calculation functions. The library is built incrementally, with new functions being added by different teams. T...
An IoT analytics team deployed a function to detect anomalies in sensor readings. However, the initial version has a 'divide-by-zero' bug. A corrected version must be deployed i...