Interesting use cases of SAS job web applications

Editor's note: this post was co-authored by Rodney Brown and Iris Chai.

In the SAS 9.4 world, SAS Stored Processes (STP) were incredibly popular. An STP is a SAS program that is stored on a server and can be executed as required by requesting applications. On SAS 9.4, they were widely used for web reporting, analytics, building web applications, delivering packages to customers and publishing results to channels or repositories. However, in the SAS Viya world, STPs have taken on a new form, which require a different method of interaction. In this article, we will walk you through how to modernize STP in SAS Viya as jobs using several use cases from our customers.

Migrating SAS Stored Processes to a SAS Viya Job

First, we must handle transferring over our deprecated STPs to SAS Viya. By using createSASPackages, a tool located within the SAS 9 Content Assessment, Stored Processes can be exported from the customer’s old 9.4 environment to their new Viya environment. Once exported, the created packages can be imported via the SAS Environment Manager. The SAS Content Assessment also provides an option to bulk import by using importSASPackages. Once imported, you can view the resulting Viya Job in Studio or Job Execution. You can see these options replicated below.

Exporting Stored Process with createSASPackages

Importing stored process with SAS Environment Manager

Bulk import using importSASPackages

Implementing SAS Jobs within R Shiny

For a previous project, a customer had multiple R Shiny apps that called SAS Stored Processes to run SAS code. R Shiny is a tool that allows building interactive web applications that can execute R code on the backend. Their R Shiny apps looks for input data from a fixed location, then outputs the information on a webapp. Customer wanted to see how her R Shiny apps could be used in their new Viya Environment. We discussed how we could take her Stored Process, migrate it to her new Viya environment, and transform it into a SAS Job. Instead of calling a Stored Process in her web app, we could call the SAS Job using Direct URL Access
Here is an example of a SAS stored process URL that the customer is currently calling:

URL in the STP that the customer is requesting from

Looking into the customers URL, it calls the host, stored process tool, then guest which allows those who do not have SAS credentials to use this link. Guest privileges must be set up in the environment for this URL to work.

SAS Jobs Executing a Job using Direct URL Access

Now, lets look at an example of the SAS Job Execution URL:

As you can see the in Blue SAS Job URL, this link and the link from earlier are very similar. This URL calls the host, the SAS Job Execution tool, the program, and the folder.

Using this SAS Job Execution URL, I can create a simple web application, using R Shiny and call a SAS Job with an HREF:

Creating a web application using the job in R Shiny

Once ran, the web application output looks like this:

Example web application and its functionality.

How to use the SAS Job Direct URL Access tool

Go to SAS Job in SAS Job Execution

Right click on job

Navigate to properties -> Details

Copy the Job URL

Demo

How to Trigger a SAS Viya Job from Web Services

The Viya Job Execution Web Application is a powerful tool designed to streamline data, execute SAS programs, and perform analytics. Let us walk through two recent examples and leverage this application effectively with you.

As a background, this client had recently migrated to SAS Viya and was keen to consolidate all processes into web applications to improve the data processing speed and the user experience.

Use Case #1: Call SAS Viya Job in R Shiny Application

In this example, the client has developed an R Shiny application to visualize data interactively. The SAS Viya Job is called in the R Shiny application and then generates the output on browsers.

Steps:

Create the Job

Configure Execution Options

Get Job Submit URLs

Insert the Job Submit URL as HREF in R Shiny

Use Case #2: Passing Key-Value Pairs in URL and Outputting in JSON Format

Steps:

Assign a global macro in the SAS program:

Set Parameters: Keep the Default parameters

Configure Query String Options:

Submit the Job in a browser:
After submission, the script will run, processing the data according to the key-value pairs provided and outputting the result as a JSON file.

To generate href link with parameter pair: _ACTION=json&_RESULTFILE=_webout.json

Monitor and Analyze:
After the job runs, check the output to ensure the JSON file is correctly formatted and contains the expected data, then review the logs for any error messages in the URL parsing or data processing stages.

Conclusion

The Viya Job Execution Web Application is a robust tool that simplifies job management in the Viya environment. Following this guide, you can efficiently submit, monitor, and manage your jobs, ensuring a smooth and productive analytics workflow.

Remember, mastering the use of this application will not only enhance your efficiency but also improve the reliability of your data-driven processes. Happy job executing!

Learn more

Viya job raw code with HTML JSON output options

Jobs: Stored processes in Viya

The Simple Guide to SAS: SQL Joins

How to create and use SAS macro functions

Interesting use cases of SAS job web applications was published on SAS Users.