When developing a brand-new SAS Viya job, it sometimes might be hard to figure out where to begin. It’s always a best practice to start with a working SAS program, but when it comes to developing a prompt form for the end user, there are many decisions to make. Should you create an HTML form? What kind of controls should you provide to the user? What parameters do you need to supply? Fortunately, SAS provides a set of sample jobs, including both code and forms, that can make getting started much easier. In this article, I’ll discuss how to use the included SAS samples to jump start your own job development.
These sample jobs are simple job definitions that contain a wide variety of job programming techniques, and demonstrate a number of different HTML input forms, from examples that enable you to select the output format and ODS style of the results generated, to jobs that generate download links for reports in various formats, to jobs that accept an uploaded CSV file as input.
In a SAS Viya environment, they can be found in the SAS Job Execution Web Application. This application can be accessed at the URL host:port/SASJobExecution. For example, the Innovation Lab URL is https://innovationlab.demo.sas.com/SASJobExecution/. The sample jobs can be found in the Samples tab in the left pane of the application.
Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.
Typically, accessing them is a one-time process. Using the SAS Job Execution Web Application, you can “install” them by copying them to a SAS content folder.
Once you’ve selected a SAS content folder, you’ll be able to view them from within SAS Studio and other applications.
You only need to do this once. Once the sample job definitions have been saved to a SAS content folder, you’ll be able to access utilize them directly from SAS Studio without returning to the SAS Job Execution Web Application.
Information and about the sample job are also included in the SAS documentation, available here.
The sample job definitions can help you quickly take create your own jobs. Let’s look at an example.
I have a working SAS program that imports a CSV file containing XY latitude and longitude coordinates and create a coordinate map:
/* Import coordinate dataset */
proc import file="/home/christine/airports.csv"
dbms=csv out=work.points replace;
guessingrows=max;
run;
/* Create map */
proc sgmap plotdata=work.points;
openstreetmap;
scatter x=x y=y / legendlabel="Points";
run;
It generates an output that looks like this:
I’d like to create a job that allows the user to easily upload their own CSV file and create a coordinate map. Rather than trying to figure out how to create a form to this from scratch, I can turn to the sample job definitions. Once of the included samples is called Upload a CSV File, and it says that it allows the user to upload a CSV file to a SAS dataset, and then displays the first 10 results.
If I run the sample job, the form looks like this:
First, I need to save the sample as a new job definition. Then I can make a few changes to the descriptive text in the HTML form so that it matches my purposes:
Next, I’ll update the code. Most of the sample code I can leave the same. The sample job definition has code that verifies that the uploaded file is a CSV file, creates a fileref, and then imports the CSV file as work.mydata. The final step is a PROC PRINT step that prints the first 10 rows of the uploaded file.
This is all I need to replace. I can simply add in my SGMAP code here instead, making sure to update the data reference to the imported CSV file:
/* Create map */
proc sgmap plotdata=work.mydata;
openstreetmap;
scatter x=x y=y / legendlabel="Points";
run;
The resulting job then allows the user to select their own CSV file:
And easily create a coordinate map, without ever having to touch any code:
Find more articles from SAS Global Enablement and Learning here.
The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.