SAS Job Execution - a loan application
- Article History
- RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
Think about digital transformation. It’s a constant and inevitable. You have a lot of code that you developed producing great calculations, statistics and graphs. So, what is the best way to present all of your work for other to consume? Do you still need to login and run your code every time? What if you automate it with APIs or jobs?
If you are a software engineer, you could easily create an application that would automate your code, but not everyone has that skill. Luckily, SAS has created functionality that is very friendly for business analysts to create automation and code execution from a HTML form. It is called SAS Job Execution.
If you have used SAS in the past, you probably have come across something called Stored Process on SAS 9. This allows you to export your code and create a web page allowing you run code through an HTML page. SAS Job Execution on SAS Viya presents a similar idea, with a couple of improvements.
SAS Job Execution – defined
SAS Job Execution is a web application that comes with SAS Viya. It allows users to create SAS code and tie it to an HTML form that can then pass parameters to the job, resulting in an output. This output takes one of many forms. In this article we explore the SAS Output page with plots and tables.
One of the good things about this web application is when you create SAS Code in a Job Execution project, it automatically becomes an API to which you pass parameters.
If you are curious on how SAS Job Execution works behind the scenes, consider looking at the overview of the SAS Job Execution Web Application page.
Create Job Execution application
Now that we understand what it is, let's go through our first SAS Job Execution app. We will follow these steps:
- Upload the data
- Generate the model Astore
- Create the SAS Job Execution file – SAS code
- Create an HTML form that ties to our SAS code
- Call the Job using the form and browser.
The scenario
For this example, think about a loan company that needs to calculate the likelihood of default on loans. The bank loan representative is responsible for aquiring and entering potential customer data into an application. The application, in turn, returns the default probability of default right away. The decision variables used are:
- LOAN - Requested loan amount
- MORTDUE - Amount due on existing mortgage
- VALUE - Value of current property
- YOJ - Years at present job
- REASON - DebtCon = debt consolidation / HomeImp = home improvement
- JOB - Occupational category
Our main asset in this project will be the pre-trained model generated by a data scientist. This file - ASTORE - represents the model binary. We will use this model to score the input data, and then, will generate a couple of plots to show the applicant how their inputs compare with the historical data - the HMEQ table.
You can find all the assets in this Github repository.
Upload the data
- In SASDrive, go to Manage Data and import the HMEQ dataset to the Public Caslib.
Generate the model Astore
- Go to SAS Studio and run the code jobexec_forest_train.sas.
- Verify the table named forest_astore exists in the Public Caslib.
Create the SAS Job Execution file
- Go to http://yourserver.com/SASJobExecution
- Create a new folder inside your personal user folder -> usually it is under /Users/yourname
- Inside this folder, right click it and select New File
- Provide a name and accept the defaults for File type (Job Definition) and Server (Compute).
- Open the file and paste the contents of jobexec.sas and save.
- Right click the Job Execution file and go to Properties -> Parameters – add values from the table below.
Name |
Default value |
Field type |
Required |
p_loan |
|
Numeric |
Yes |
p_mortdue |
|
Numeric |
Yes |
p_value |
|
Numeric |
Yes |
p_yoj |
|
Numeric |
Yes |
P_reason |
|
Character |
Yes |
P_job |
|
Character |
Yes |
_action |
Form |
Character |
Yes |
_CASHOST |
<your SAS server> |
Character |
Yes |
Create an HTML form
- Right click the Job Execution file, go to Edit and select New HTML form.
- Paste the contents of the index.html file in the new tab.
- Find and update the value parameter in the following section to match the file path for your environment:
<!-- Change the path to match your job execution file. -->
<input type="hidden" name="_program" value="/Users/ludepa/JES/scoringJob">
- Save the file.
Call the Job
- On the Job Execution file tab, click submit and you should see something like the image below.
Loan application form
- Fill in sample data in the form and click Run Code. Your output should resemble the following:
Loan application results
Note: the first time I submitted the form, I received an error. Referencing to the logs (the gear icon on the Job Execution screen) alerted me of a connection error. It turns out in my multi-node environment, I had to provide the fully qualified URL for the CAS controller in the _CASHOST_ parameter. This will vary from deployment to deployment.
As you can see in the response, this application is approved. The generated SGPLOTs represent how the scored data compares against the historical data used to train this model. Let’s take the first graph as an example.
- The title is: “You requested $2000 – here is how it compares to historical data.”
- This input value ($2000) is represented with a red dotted line.
- Here, about 0.5 percent of the loan requestors, asked for a loan of $2000.
The goal of these graphs is to show to the analyst how the request compares against the population this model knows. It helps as a guide providing feedback for the data scientists or to explain to the customer why they might have been denied a loan.
The video below outlines the step-by-step process of the example explained in this article. I added some comments on the video so you can follow along.
- Chapters
- descriptions off, selected
- captions settings, opens captions settings dialog
- captions off, selected
- en (Main), selected
This is a modal window.
Beginning of dialog window. Escape will cancel and close the window.
End of dialog window.
This is a modal window. This modal can be closed by pressing the Escape key or activating the close button.
Finally
As we saw in this article, you can take your code and wrap it around an API using the SAS Job Execution. You can pass parameters to your code through macro variables and create HTML forms that connects to your code. Job Execution enables you to call SAS code from other applications or use the generated form to embed it into applications. This is an easy and intuitive way to organize your codes as well as share them.
In the next article, we will learn other features from SAS Job Execution - the SAS Job Flow Scheduler, where we will schedule a job to run using the scheduler.
Related resources
- SAS Job Execution documentation
- Running Your SAS Code from the Web Using the SAS Job Execution Web Application - SASGF 2020 super demo by @Vince_SAS
- APIs in action: build an automated profiler with SAS Viya - SAS Community article by @Clare_Casey