BookmarkSubscribeRSS Feed

Overloading functions in Intelligent Decisioning

Started ‎06-15-2022 by
Modified ‎06-15-2022 by
Views 311

In SAS Intelligent Decisioning you can write your own custom functions to enhance its set of functions if you have code that you want to use more often or in different Decision Flows.

Sometimes it may be useful to have one function that accepts different sets of input parameters. So, you can call the same function in a different way depending on its use case. For this a programming language needs to support ‘function overloading’. SAS DS2, the programming language in Intelligent Decisioning, does support ‘function overloading’.

 

Writing overloading functions

To write an overload function in Intelligent Decisioning we have to use a custom context file rather than writing a custom function directly in Intelligent Decisioning.

To create a custom context file, go to Code files in Intelligent Decisioning click on ‘New Code File’ and choose file type ‘Custom Context’

ClemensKnobloch_27-1655310111106.png

In the file you can write different variants of your overload function which have the same name but different input parameters.

In this example we have a function (or method as it is called in DS2) that calculates the fuel economy for a given list of vehicles. We have two flavours of the same function:

  • The fist specification takes two input parameters. One parameter (datagrid) with a list of vehicles, the driven distance, and the used fuel. A second parameter (datagrid) to hold the output with calculated fuel economy for each vehicle in parameter one.
    We calculate the fuel economy by reading the necessary values from parameter one and write the result into parameter two.
  • The second specification takes only one parameter, the same as in the first specification. But in this variant of the function, we add columns to the list of vehicles that are passed in and output the fuel economy to the list.
ClemensKnobloch_28-1655310173031.png

 

Calling overloaded functions

When we have written the function (fuelEconomy()) we can call it from a DS2 code node, a custom function or from a Rules Set. Depending on the use case we can call the function in two different ways.

To call a function that is in a custom context file we need to call it via its qualifier ‘application’ using the format: application.method_name(arguments);

In a Rule Set for example we can call the function like this:

ClemensKnobloch_29-1655310224981.png

We pass in the list of vehicles in parameter vehicleList:

ClemensKnobloch_30-1655310248949.png

And receive the fuel economy in parameter ecoList:

ClemensKnobloch_31-1655310280170.png
 

Alternatively, we can call the function like this:

ClemensKnobloch_32-1655310303644.png

Where we only pass in the parameter vehicleList:

ClemensKnobloch_33-1655310323661.png

And receive the fuel economy also through parameter vehicleList:

ClemensKnobloch_34-1655310340389.png

To test the Rule Set we have to make the Rule Set aware of the custom context file, so it can find the function we have written. In the Rule Set go to Properties and set the custom context file in field: Test custom context.

ClemensKnobloch_35-1655310357614.png

(The same applies when testing DS2 code files)

 

Associating a Custom Context File with a Decision

Custom Context files can only be used with published Decision Flows and not Rule Sets.

For a Decision Flow to pick up a custom context file we need to associate it with the Decision Flow where we use it. In the Decision Flow go to Properties to set the custom context file. There are two entries for custom context files as you can use different files for executing the decision flow in CAS or MAS respectively.

ClemensKnobloch_36-1655310393198.png

Summary

To enrich the set of functions in Intelligent Decisioning you can write overload functions by using Custom Context files. These functions can then be called in DS2 code files, custom functions, and Rule Sets.

Version history
Last update:
‎06-15-2022 12:37 PM
Updated by:
Contributors

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Tags