blog

Bridge Your Analytical Code Gaps: How to Build Custom Applications with SAS Viya

02/03/2020 by Sean Ankenbruck Modernization - Analytics

The open source community can now access the SAS brand’s industry-leading machine learning algorithms from almost any programming language. This has been made possible by SAS Viya and its ability to leverage the entire SAS brand to a wider audience. You can even take these algorithms a step further by integrating them into your existing web applications. We will examine a case study comprised of a solution developed for one of our customers using PHP, SAS and a Python function to bridge the gap.

The Problem: Running Code in Real Time

Our customer is a financial services firm that specializes in the auto-lending industry. In one aspect of their business, they use proprietary models to determine whether a lender should approve an auto-loan for a customer. These models are written exclusively in SAS code and were originally executed via a batch process at some predetermined time interval.

The firm came to us with a simple request: How can we take our SAS code that currently runs in batch and modify it to run in real time with SAS Viya?

They had recently purchased Viya with the intention of using the open source capabilities to call SAS code from within an existing web application that was developed with PHP. Their hope was that these capabilities would allow them to score customer information in real time instead of relying on a batch process or a cron job to score the data periodically. When a user submitted their information they wanted their application to simultaneously submit the data, score it and retrieve results without the user noticing any sort of delay in the process.

At Zencos, we thrive on the ability to work with customers and help them solve unique and complex problems with custom solutions fine-tuned to meet their individual needs. When this problem was presented to us, we knew it would be a perfect use case for the Python SWAT package.

The Solution: Use Python To Bridge the Gap

The Python SWAT package provides direct access to CAS using Python conventions and data structures.

What does that mean?

Ultimately, it means you can write Python code while also tapping into the analytical and data management capabilities of CAS – the cloud infrastructure on which SAS Viya is built.

We saw an opportunity here to use the SWAT package to serve as a connection between the web application (developed in PHP) and the proprietary score code (developed in SAS). The PHP application on its own did not have the ability to call or submit SAS code, and their SAS score code didn’t have the ability to collect data directly from a web form within the PHP application.

We created a Python program to bridge the gap between the PHP application and the SAS code. This allowed us to handle all web related requests with Python functions and handle all SAS Viya related requests with the SWAT package.

The process begins when a user accesses the web application. They fill out an HTML form and submit their information. When the form is submitted, the PHP application calls the Python program.

This program converts the data to a Python dataframe which is then transmitted to CAS and stored as a CAS table where it is accessible to the model code in SAS Viya. Once the data is scored, the results are retrieved from the server and converted to JavaScript Object Notation (JSON). The resulting JSON data is finally sent back to the PHP application via a POST request.

The entire process is abstracted in the following diagram:

The Result: A Working Solution and Endless Possibilities

With the creation and implementation of this Python program, our customer was able to drastically reduce the amount of time it took to assess potential customers using their product.

A simple solution using Python SWAT allowed our customer to move away from batch processing and into real time analytics. All of this was accomplished without having to modify any of their existing model code.

This case study is just one example of how SAS Viya has opened the door to a plethora of new possibilities for businesses that want to integrate SAS software with new and existing applications. You can read about other implementations including anti-money laundering (AML) and text analytics at the Zencos blog.

We see this as a major opportunity for those companies that currently use SAS for analytics and would like to extend those analytics to work seamlessly with some other application regardless of the language of choice. For an introduction on how to get started, please reference my previous blog post here.