The question about how to schedule a SAS Studio 5.1 (Studio V) job in SAS Viya has come up from several people recently, so I decided to write an article that gives a step-by-step example of how to do this.
The process of scheduling a SAS Studio 5.1 (Studio V) program involves the following steps:
Write and save the SAS Studio 5.1 program(s) you want to schedule
Determine the host and port for the job schedule execution
Write the code to call the SAS Studio 5.1 program(s) you want to schedule
Create and submit the SAS Job Execution code
Schedule the Job in SAS Environment Manager.
As part of this article, I will use an example to walk through each of these steps.
Write and save SAS Studio 5.1 program(s)
First you need to write and save the program(s) in SAS Studio 5.1 that you want to be part of a scheduled job execution. In my case I have two SAS Studio 5.1 program files that I want to be called one after the other in a scheduled job.
The first program file called Generate CSV File Example.sas uses proc export to write all the cars of type Sedan to a CSV file.
Select any image to see a larger version.
The second program file called Load File to Memory Example.sas drops a table called CARS_CSV from the Public caslib and then loads the CSV file created by the previous program and promotes the table CARS_CSV to the Public caslib.
Both of these program files have been saved in a folder called gelcontent within the SAS Content section of SAS Viya in SAS Studio 5.1.
Determine host and port for job schedule execution
Now that I have the program file(s) to call, I need to determine the host and port to use for the job schedule execution. To do this, I go to the Servers page in SAS Environment Manager. The host and port listing for the CAS Controller is the one you want to use. In my case, that means the host is intcas01.race.sas.com and the port is 5570.
Write code to call the SAS Studio 5.1 program(s)
Next, you can test your code by writing and testing a program in SAS Studio 5.1 to execute the program(s). Alternatively, you can perform this step directly in the SAS Job Execution web application.
First, you need to define the CAS session with the appropriate host, port, and any wanted sessopts. Next, you need to use the following syntax to reference and include the file with SAS program.
filename <JobName> FILESRVC folderpath='<program_folderpath>' filename='<program_filename>';
%include <JobName> / source;
Repeat this code for any other program files you want to reference and then finally you terminate your CAS session.
The code for my example looks like this:
I submit the code and confirm that the CARS_CSV table was loaded to the Public caslib.
Now that you've confirmed that the code works, copy the code from this test file, so you can later paste it in a SAS Job Execution file.
Create and submit SAS Job Execution code
To open the SAS Job Execution application, enter http://ViyaServerName/SASJobExecution/ in a web browser.
On the Content tab, navigate to the folder where you want to store the job execution file and click to create a new file in the selected folder.
Enter a name and description for the job execution file. Select the file type of Job definition. Then, click OK to create the new file.
With the new file name selected, click to edit the contents of the file.
In the edit window for the job execution file, paste the code you copied previously from your SAS Studio 5.1 test job. Note: You must use Ctrl + V to paste the copied code. Click to save the code. Click to submit and execute the code in the Job Execution file.
Submitting the job opens a SAS Output tab for the contents from the executed file. Since the job I ran has no content to display, the tab is empty.
You can close this tab after reviewing it. Back on the Content tab, click Close to close the edit window for the file.
You may also want to consider adding parameters to your SAS Job Execution file. One way to do this is to use the application's Job Submit Options which will apply to all submitted jobs for your browser session until you change the options.
In the example below, I have set the parameter _output_type=none which means the SAS Output tab will not be displayed after submitting the job. I have also checked the box for Show log which means the SAS Log will be displayed when submitting the job.
Select the Jobs tab, to view the executed jobs and their status. Confirm that the job that was just executed has a status of .
A successful execution indication on the Jobs tab doesn't necessarily mean all steps within the program ran successfully, it just means the program itself executed. Therefore, I confirm that the CARS_CSV table was loaded to the Public caslib as expected by the steps within the program.
Note: It has a later date and time than when I ran the test in SAS Studio 5.1.
For more information on the SAS Job Execution web application, please refer to the documentation.
Schedule Job in SAS Environment Manager
Now that the SAS Execution Job has been tested successfully, the job can now be scheduled. To schedule the job, on the Jobs tab in SAS Job Execution select the job you want to schedule and click .
This will add a job entry on the SAS Environment Manager – Jobs tab and open that application. On the SAS Environment Manager – Jobs tab, select the Scheduling section and select the SAS Job Execution job that was just added. Click to create a schedule for the job.
Now you can schedule the job as usual in SAS Environment Manager. For example, if I want to run this job every day at noon New York time, I would create the following trigger and enable it.
The job is now scheduled to run at the specified trigger time.
For more information on scheduling jobs in SAS Environment Manager, refer to the documentation.
After the time has passed for the scheduled job to run, I first confirm on the SAS Environment Manager – Jobs tab in the Monitoring section that the scheduled job executed successfully.
Then, I confirm that the CARS_CSV table was loaded to the Public caslib.
Note: It has a later date and time than when I ran the file in the SAS Job Execution application. The date and time correspond to the scheduled time for the job in SAS Environment Manager.
Thanks for reading this article on how to schedule a SAS Studio 5.1 (Studio V) job in SAS Viya. Here is a related article that you may find of interest: Making SAS Programs stored on the filesystem available to SAS Viya folders
Thanks to my colleague, Clemens Knobloch, for his work on this subject that I leveraged to write this article.
... View more