fcmpact

addRoutines

Description

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.

fcmpact.addRoutines result=<results> status=<rc> / appendTable=TRUE | FALSE, funcTable={<casouttable>}, library="string", package="string", routineCode={"string-1" <, "string-2", ...>}, saveTable=TRUE | FALSE;
Settings
ParameterDescription
appendTableWhen set to TRUE, this option appends the new functions to an existing FCMP table. If FALSE, it overwrites the table. The default is FALSE.
funcTableSpecifies 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.
librarySpecifies an existing FCMP library to load. This is useful for referencing functions or subroutines that are already compiled and stored.
packageDefines the name of the FCMP package where the functions and subroutines will be stored. Packages help in organizing and avoiding name conflicts.
routineCodeA 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.
saveTableWhen 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.
Data Preparation View data prep sheet
Data Creation

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.

Copied!
1/* No
2data creation is needed for this action, as it generates a function table from code. */

Examples

This example compiles a simple function named 'myadd' that adds two numbers and stores it in a CAS table named 'myfuncs'.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC 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};
6RUN;
Result :
The action will create a CAS table named 'myfuncs' in the 'casuser' caslib, containing the compiled 'myadd' function within 'mypackage'. A confirmation note will be displayed in the log.

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.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC 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;
10RUN;
Result :
A CAS table named 'mymathfuncs' is created in the 'casuser' caslib and also saved as a physical file (e.g., mymathfuncs.sashdat). The table contains both the 'myadd' and 'mymultiply' functions. The log will indicate the successful creation and saving of the table.

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.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC 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;
14RUN;
Result :
After the first step, the 'myaggfuncs' table contains the 'myadd' function. After the second step, the same table is updated to contain both 'myadd' and 'mysubtract' functions within the 'myaggpackage'. The log will show notes for both actions.

FAQ

What is the purpose of the addRoutines action?
What is the 'appendTable' parameter in the addRoutines action?
How do you specify the output table for the addRoutines action?
What is the role of the 'library' parameter in the addRoutines action?
What is the 'package' parameter used for in the addRoutines action?
How is the FCMP routine's code provided to the addRoutines action?
What does the 'saveTable' parameter control in the addRoutines action?

Associated Scenarios

Use Case
Standard Use Case: Tiered Customer Discount Calculation

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...

Use Case
Large-Scale Use Case: Appending Functions to a Financial Risk Library

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...

Use Case
Edge Case: Hotfix Deployment by Overwriting a Buggy Function

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...