Version 2.2 of the SAS Viya Job Execution Web Application Service has some fantastic new features which can enable developers to create custom applications to meet specific reporting needs. Specifically this version delivers the ability to store HTML input forms, prompts, and source code within a single job definition. When you copy or move a job, all these elements move with it.
Pretty sweet! In this post, I'll show you how to rebuild this example using the Job Execution WebApp Service. Let's get started!
We'll start within the Job Execution WebApp by creating a new job. In the screenshot below, I'm creating a job in the folder "/Public/JES_Example"
Give your job a name. In my example, the job is named "PromptAndDisplay".
All other options can remain as their default values.
The first thing we will need is some SAS code for our job to execute. You can add this by right-clicking the job and selecting: "Edit" -> "Source code"
From here you can add SAS Code to the job and save it.
In my example below, I'm adding SAS code which simply prints out either the Males or Females from sashelp.class table:
Notice that the code above is expecting a SAS macro variable "genderParameter" for both the ODS title and the where clause in the PROC PRINT step. This will be passed into the job from the HTML form that we will now create.
In order to create a prompt for the user, we will add an HTML form to our job. To do this right-click the job and select: "Edit" -> "New HTML Form":
Let's begin by first creating the basic HTML page with a user selection:
Nice! We have created our simple input form. If you'd like to see what it looks like, right click on your job and choose: "Display form" -> "HTML form"
Looking at this script more closely, we can see that a simple function named "submitForm" is created. It should be noted that the "submitForm" function is bound to the form that was placed in the body tag. Next the formData variable is declared and several input parameters are appended; most importantly are "genderParameter" and "_program". The "genderParameter" parameter contains the user's selected value from the drop down in the body tag. The "_program" parameter must be the full path of the JES job you are currently building. Hence, in the example above we will replace the "<-JES Job Full Path->" string with the full path to our JES job. Which is "/Public/JES_Example/PromptAndDisplay":
And that's it! You're done with the coding part of creating the example. All that's left is for us to add a job definition parameter so the HTML input form will be displayed before the job is executed. This is easily done by right-clicking the job and selecting: "Properties":
From here, select "Parameters". Click "Add a new parameter". Apply the following values:
On GitHub, you will find all the code discussed in this article. All code intended to be saved in a SAS® Job Execution Web Application 2.2 job definition within a Viya 3.5 environment.
On Github, you will find the following support files for this article:
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.