This guide will walk you through adding Python code files to a decision flow in SAS Decision Builder, allowing you to customize approval and denial messages based on the decision outcome. We’ll also show you how to adjust a rule set on the fly to include necessary variables. Let’s get started!
Want to see these steps in action? You can also watch our Integrating Python Code in Decision Flows video guide to add python code files to your decision flow in SAS Decision Builder. The video walks through each stage of the process, making it even easier to follow along and get started!
Step 1: Create Python Code File for Approval Messages
- Create a New Python Code File: Start by creating a Python code file to generate an approval message.
- Write the Code: Enter the Python code that will send a custom approval message based on the decision outcome.
- Save the Code: Click Save. Upon saving, the system will automatically add any variables referenced in the code to the Variables tab of the Python code file.
Step 2: Update Data Types for Variables
- Go to the Variables Tab: In the Python code file, navigate to the Variables tab.
- Adjust Data Types for Specific Variables:
- Set
LOAN
to Decimal.
- Set
TERM
to Integer.
- Set
OFFER_RATE
to Decimal.
This ensures that the data types match the data being processed.
Step 3: Create Python Code File for Denial Messages
- Create Another Python Code File: Repeat the process to create a Python code file that generates a denial message.
- Write and Save the Code: Enter the code to send a denial message and save the file. Variables will again be added automatically to the Variables tab if referenced in the code.
Step 4: Add Branches to Handle Different Loan Outcomes
- Navigate to the Decision Flow: Go to the Loan_Request_Review decision flow in SAS Decision Builder.
- Add Branches for Different Outcomes:
- Right-click on the Ruleset step and select ‘Add Branch’.
- Create branches for the ‘Approved’, ‘Denied’, and ‘Review’ paths based on the
Loan Status
variable.
This allows you to control the decision flow based on each loan outcome.
Step 5: Add Python Code Files to Each Branch
-
Add the Approval Message File:
- Right-click on the ‘Approved’ branch and choose Python code file.
- Select the Loan_Approved_Message file to send a customized approval message.
-
Add the Denial Message File:
- Right-click on the ‘Denied’ branch and choose Python code file.
- Select the Loan_Denied_Message file to send a denial message.
Step 6: Ensure Required Variables are Available in the Decision Flow
Before running the decision flow, ensure that all necessary variables are set up, particularly the TERM
variable that is used in the approved message python code file.
- Go to the Variables Tab in the Decision Flow: Check the Variables tab to confirm all required variables are present.
- Navigate to the Initial_Loan_Review Rule Set:
- In the decision flow, click on the rule set name (e.g., Initial_Loan_Review) to edit the rule set.
- Add and Define the TERM Variable:
- In the rule set, go to the Variables tab and add a new variable named TERM.
- Set the Data Type to Integer, mark it as an Output Variable, and set a fixed value of 24 (for a 24-month loan term).
- Save the changes and return to the decision flow.
Step 7: Run the Decision Flow and View Results
-
Run the Decision Flow:
- Click the Run button.
- Select the input dataset that contains loan application data.
- Choose a destination in your lakehouse for the output results.
-
View Decision Outcomes:
- After running the decision flow, go to the destination table in the lakehouse to review the decision outcomes.
- Check the output messages to see the custom approval or denial messages generated by the Python code files based on the loan status.
And that’s it! You’ve successfully added Python code files to a decision flow, adjusted rule sets on the fly to include key variables like the loan term, and customized messages based on loan status outcomes. This process provides a flexible way to deliver personalized messaging within automated decision flows in SAS Decision Builder.