BookmarkSubscribeRSS Feed

SAS Job Execution - a loan application

Started ‎09-18-2020 by
Modified ‎07-10-2020 by
Views 7,859

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:

 

  1. Upload the data
  2. Generate the model Astore
  3. Create the SAS Job Execution file – SAS code
  4. Create an HTML form that ties to our SAS code
  5. 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

  1. In SASDrive, go to Manage Data and import the HMEQ dataset to the Public Caslib.

 

Generate the model Astore

  1. Go to SAS Studio and run the code jobexec_forest_train.sas.
  2. Verify the table named forest_astore exists in the Public Caslib.

 

Create the SAS Job Execution file

  1. Go to http://yourserver.com/SASJobExecution
  2. Create a new folder inside your personal user folder -> usually it is under /Users/yourname
  3. Inside this folder, right click it and select New File
    1. Provide a name and accept the defaults for File type (Job Definition) and Server (Compute).
  4. Open the file and paste the contents of jobexec.sas and save.
  5. 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

  1. Right click the Job Execution file, go to Edit and select New HTML form.
  2. Paste the contents of the index.html file in the new tab.
  3. 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">
  1. Save the file.

 

Call the Job

  1. On the Job Execution file tab, click submit and you should see something like the image below.

Loan application formLoan application form

 

  1. Fill in sample data in the form and click Run Code. Your output should resemble the following:

Loan application resultsLoan 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.

 

 

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

 

 

 

 

Version history
Last update:
‎07-10-2020 09:55 AM
Updated by:

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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