Recently we were approached by a customer to tackle the following business challenge in their SAS Viya environment.
The customer’s marketing operations team needed an easy-to-use tool allowing them to compare two different populations:
This exercise would provide value for internal teams, exposing how particular audiences differed from the whole (e.g. responded to an email offer vs. no response). The solution required flexibility and allow the end-user to quickly assign and select different attributes to compare (such as acquisition channel and credit worthiness). The other requirement was for the solution to be automated and therefore shorten the time for the marketing team to take action.
We recognized by creating the application for this requirement we'd cover many other use cases for automation (simple to complex). Our SAS team designed a solution combining the ease and customization of a SAS Visual Analytics front-end with the automation and flexibility of SAS Job Execution Web Application. This was developed in SAS Viya version 3.5 on a cloud instance.
We’ll start by building a simple report with static data. Afterward, we’ll embed a script to enable automatic updates when the user provides new data.
Let’s begin in SAS Visual Analytics. From a blank report, we can drag and drop visualizations into the workspace and assign data. Our simple report design includes:
This video shows how to build this basic report and begin to populate data variables.
Did you know…Visual Analytics allows you to join multiple tables directly in the report editor? It’s easy. Watch the video below for details.
Now that we’ve set up the profiler comparison dashboard let’s set up the user-input page. Create a new tab and drag in the Web Content object.
On the Options tab, the Web Content section is where we’ll insert our automated script. We’ll come back to this once our script is created.
You can include more customized design features and align with your corporate style guides to increase user adoption. For tips on designing interactive and intuitive reports in SAS Visual Analytics refer to the following resources:
Next, let’s look at how to create the automated script and HTML.
Why re-create the wheel? We’ll use the out-of-the-box example scripts provided in SAS Job Execution as a starting point to accelerate our development.
Access the sample scripts at http://<host>/SASJobExecution/samples
For this application, we used “Upload a CSV File” sample. You can select the check box next to it and then use the Copy To button in the top right to copy the sample to your location. Watch the video below for a demonstration.
Once you’ve copied the sample, you can navigate back to Content and open your file.
We made a few enhancements to the sample source code in “Upload a CSV File.”
/* Set the options necessary for creating a connection to a CAS server. */
/* Once the options are set, the cas command connects the default session */
/* to the specified CAS server and CAS port, for example the default value */
/* is 5570. */
/*****************************************************************************/
cas mySession host='<server>' port=5570;
NOTE: added this section to the file; replace <server> with your CAS host
proc import datafile= upload
out=work.Customer_List_in
dbms=csv
replace;
getnames=yes;
run; quit;
NOTE: replaced the ‘out’ value
data work.Customer_List_stg (drop=customer_id_old);
set work.Customer_List_in (rename=(Customer_ID = customer_id_old));
length Customer_ID $16.;
Customer_ID = put(customer_id_old, 16.);
run;
NOTE: Added this section to the file. This is important for the data join. If your VA report does not load correctly, check that the variable name matches correctly.
*****************************************************************************/
/* Drop Customer_List from Public and load/promote imported file */
/*****************************************************************************/
proc casutil;
droptable casdata="Customer_List_new" incaslib="Public" quiet;
*promote casdata="Customer_List_stg" casout="Customer_List" incaslib="Public" outcaslib="Public";
load data=work.customer_list_stg casout='customer_list_new' outcaslib='Public' promote;
quit;
NOTE: added this section to the file
data _null_;
length filename $1024;
filename = htmlencode(strip("&_WEBIN_FILENAME"));
call symputx('_WEBIN_FILENAME', filename);
/* if (upcase("&_WEBIN_FILEEXT") ne 'CSV') then do; */
/* rc = dosubl('ods _all_ close;'); */
file _webout;
put '<!DOCTYPE html>';
put '<html>';
put '<head><title>File Loaded</title></head>';
put '<body>';
put '<h2>Uploaded file "' filename +(-1) '" is now available as Customer_List.</h2>';
put '<h2>You may now refresh your report and close this window.</h2>';
put '</body>';
put '</html>';
abort cancel;
/* end; */
run;
NOTE: added this section to the file
Modify the HTML form as needed. Access the HTML by right clicking on your Job Definition and going to Edit > HTML form as shown here:
NOTE: In this example we are using SAS Viya version 3.5. If you are using Viya 3.4, you need to copy both the Job Definition and the Job Form from the Sample page and you’ll see them as two separate elements.
The following highlights key updates in the example script.
<body role="main">
<div>SAS<sup>®</sup> Job Execution</div>
<h1>Upload a CSV File</h1>
<p>
Use this page to upload a CSV file from your local
machine to the SAS server machine.
</p>
In the following code, the hidden input types serve as job parameters
<form action="/SASJobExecution/" method="post"
enctype="multipart/form-data">
<input type="hidden" name="_program" value="$PROGRAM$">
<input type="hidden" name="_action" value="execute"/>
<input type="hidden" name="_output_type" value="ods_html5"/>
<input type="hidden" name="_csrf" value="$CSRF$">
<input type="hidden" name="_odsstyle" value="HTMLBlue">
<input type="submit" value="Upload Data" class="pointer"/>
<input type="checkbox" name="_debug" id="_debug" value="log" class="pointer"/><label for="_debug">Show SAS Log</label>
Once we have the Job Execution SAS code and the HTML form, locate the endpoint to embed in the front-end report.
Right-click on your Job Execution project, then select Properties, and open the Details tab.
Copy the Job submit action and paste this back to your Visual Analytic web form.
Let’s return to Visual Analytics to complete the application. In the web content form, go to Options and then enter the job submit URL under Web Content.
Save the report and select View Report to test functionality.
Congratulations! If you’ve followed along through this article, you now have access to the final application.
Clone the assets used in this article from the sas-viya-job-execution-service-automated-profiler GitHub repository.
You’ll need the Upload_a_CSV_File_definition.json file to configure the automated script in SAS Job Execution. As discussed previously, in Viya 3.5, the job definition and the job HTML are contained in the one file.
Import the json file and the VA report via the SAS Environment Manager > Content > Import button.
Make the following required modifications.
We've demonstrated how to build an application using a prepackaged sample in the SAS Viya Job Execution Web Application. The customer was quite pleased with the POC we created. In fact, they were impressed at how easy the process was to complete. They immediately realized the benefits and took this approach to create several other applications.
Job Execution 2.1 User Guide (PDF)
Job Execution 2.1 User Guide (Web-based)
SAS communities: Creating a Job in VA 8.3 via Job Execution Web Application
Data Entry in SAS Visual Analytics 8.3 Blog Post
Amazing product, team!
This is a really cool solution! Great job!
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!
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.