BookmarkSubscribeRSS Feed

Get a Head Start: Using SAS Viya Job Samples

Started ‎11-18-2024 by
Modified ‎11-27-2024 by
Views 2,371

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.

 

What are sample jobs?

 

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.

 

How do I access the sample jobs?

 

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.

 

01_treiman_sample_01-1.png

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.

 

02_treiman_sample_02.png

 

Once you’ve selected a SAS content folder, you’ll be able to view them from within SAS Studio and other applications.

 

03_treiman_sample_03.png

 

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.

 

How do I use the sample jobs to create my own job?

 

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:

 

04_treiman_sample_04.png

 

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.

 

05_treiman_sample_05.png

 

If I run the sample job, the form looks like this:

 

06_treiman_sample_06.png

 

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:

 

07_treiman_sample_07.png

 

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.

 

08_treiman_sample_08.png

 

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:

 

09_treiman_sample_09.png

 

And easily create a coordinate map, without ever having to touch any code:

 

10_treiman_sample_10.png

 

Tips and Tricks

 

  • When uploading CSV files, it’s a good idea to add additional validation code to make sure that uploaded file is appropriate for the code being run.
  • If you’re using multiple uploaded files, they can be referenced by &_WEBIN_FILENAME1, &_WEBIN_FILENAME2, and so on.
  • If using dynamic prompts, make sure that the table being used has been made available to the compute context being used by the job.

 

 

Find more articles from SAS Global Enablement and Learning here.

Version history
Last update:
‎11-27-2024 10:45 AM
Updated by:
Contributors

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

SAS AI and Machine Learning Courses

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.

Get started

Article Tags