BookmarkSubscribeRSS Feed

SAS Viya 3.4: Schedule SAS Studio 5.1 (Studio V) Program Files

Started ‎04-11-2019 by
Modified ‎09-18-2019 by
Views 13,198

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.

 

1_Job1.png

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.

 

2_Job2.png

 

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.

 

3_SavedJobs.png

 

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.

 

4_HostPort.png

 

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:

 

5_ProgramTest.png

 

I submit the code and confirm that the CARS_CSV table was loaded to the Public caslib.

 

6_CARS_CSV.png

 

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.

 

7_CopyProgram.png

 

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 1_IconCreate.png to create a new file in the selected folder.

 

8_CreateJob.png

 

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.

 

9_JobName.png

 

With the new file name selected, click 2_iconEdit.png to edit the contents of the file.

 

10_EditJob.png

 

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 3_IconSave.png to save the code. Click 4_IconSubmit.png to submit and execute the code in the Job Execution file.

 

11_SubmitJob.png

 

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.

 

12_SASOutput.png

 

You can close this tab after reviewing it. Back on the Content tab, click Close to close the edit window for the file.

 

22_CloseJob.png

 

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.

 

23_JobSubmitOptionsIcon.png

 

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.

 

24_JobSubmitOptions.png

 

Select the Jobs tab, to view the executed jobs and their status. Confirm that the job that was just executed has a status of 5_IconSuccess.png.

 

13_JobSuccess.png

 

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.

 

14_CARS_CSV.png

 

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 6_iconSchedule.png.

 

15_JobSchedule.png

 

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 7_iconSchedule.png to create a schedule for the job.

 

16_ScheduleJob.png

 

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.

 

17_JobTrigger.png

 

18_ScheduleJob.png

 

The job is now scheduled to run at the specified trigger time.

 

19_ScheduleJob.png

 

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.

 

20_JobSuccess.png

 

Then, I confirm that the CARS_CSV table was loaded to the Public caslib.

 

21_CARS_CSV.png

 

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.

Comments

Thank you for useful example.

I tried scheduled submit. But when I clicked [Submit] to execute the code in the Job Execution file, an error (time out) was occurred.  I could execute below code in SAS Studio on SAS Viya for 215.234 seconds.  Is there wrong in my code?

 

(ds2_program.sas makes some datasets in mysas library(not CAS) using some tables in Hadoop)

---

cas MySession host="XXXXX" casport=5570 sessopts=(timeout= 3600 locale="en_US");

libname mysas '~/MySAS';

filename SXXXX FILESRVC folderpath='/Users/XXXXX' filename='ds2_program.sas';
%include SXXXX / source;

cas MySession terminate;

---

Katsunari

Glad you found the post useful.  Sorry I'm not sure what is wrong with your code.  If you are still having the issue, I suggest you contact Tech Support.

I will contact Tech Support. Thank you (^^)/

 

I have one more question.

Why can't we open SAS Job Execution application from SAS Drive?

(To open the SAS Job Execution application, enter http://ViyaServerName/SASJobExecution/)

 

Katsunari

Sorry...I'm not sure why it's not on the drop-down menu.
mpg

This was an incredibly helpful post! Thank you so much for putting it together.

 

One minor suggestion... the code block for calling the SAS Studio program is missing an apostrophe to close the program_filename reference.

filename <JobName> FILESRVC folderpath='<program_folderpath>' filename='<program_filename>';
%include <JobName> / source;

Thanks for reading the article and catching that issue.  I have updated the text.

How can save print log file from the code ?

 

  WIll proc printo log="filename.log"; run;  in the execution file work ?

 

 

Thanks a lot MKQueen for the detailed explanation.

 

I would also like to know if there is a way in the job submit options to open a web page(like a VA report link ) as an ouput after the job has been submitted and completed successfully using the Job Submit URL?

 

My requirement is to submit a job using the job submit url(Advanced parameters) which loads the table to CAS and once the program is run sucessfully it should load the VA link of the Report (Normally this table is linked to the VA Report).

I tried to add a piece of html in the Job code like the below

 

Samplejob code

---------------------

/*

Code to include the SAS Code for execution

*/

data _null_;

file _WEBOUT;

put '<html>';

put <body>;

put <a href="Link to the VA report">Click Here</a>;

put </body>;

put</html>;

 

But the above code gives a link after the job completes successfully. But my desired result is load the VA report link/webpage once the job execution is completed successfully.

 

Also I have tried using the meta tag for autorefresh of the page. But once the job is submitted , its not redirecting the page to the specified url in the web browser.

 

Thankyou so much for the help in Advance.

 

Add this input parameter to your job: _OUTPUT_TYPE: html

 

Specify this DATA step code to display the report:

 

data _null_;
file _webout;
put '<script>';
put 'window.onload = function() {';
put '  window.location.href = "link-to-VA-report";';
put '}';
put '</script>';
run;

  

Then run the job in a new browser tab:

 

http://your-server/SASJobExecution?_program=/folder-location/job-name

 

Vince DelGobbo

SAS R&D

Thanks a lot Vince. Your Solution worked perfect!!

 

Also I am trying to add a condition just above the datastep to load the page only if there are no errors in the previous steps. But the syserr is unable to capture the error from proc Casutil.

I have intentionally introduced an error (Error: File work.dsname does not exist ) in the proc cas util and checked if the syserr is returning the code, but its not.

 

Is there any special way to handle errors in SAS Viya? I have gone through many documents but couldn't figure out any.

 

Thanks for the help in advance!!

 

 

 

Hi

 

It is a very good article. I want to know if we can create job dependency and job controls within the job definition file

say for ex?

 

filename job filesrvc folderpath='/path' filename='prog1.sas';
%include job / source;

some controls like syserr etc? and if only no error in pervious step , proceed.

filename job filesrvc folderpath='/path' filename='prog2.sas';
%include job / source;

 

is this possible?

Maybe something like this?

 

filename job filesrvc folderpath='/path' filename='prog1.sas';
%include job / source;

%if (&SYSERR ne 0) %then %do;
data _null_; abort cancel nolist; run;
%end;

filename job filesrvc folderpath='/path' filename='prog2.sas';
%include job / source;

 

Vince DelGobbo

SAS R&D

 

Hi, 

 

Thank you for this insightful article. 

 

I am scheduling in SAS Viya 3.5 and I am running into an issue where there is a limitation in how the jobs are triggered. 

 

My dilemma is how to schedule a job to run during business hours, 8:00 -17:00. 

 

This does not seem possible given the available triggers has anyone found a way to manage this requirement?

@JessLund  Yes...Unfortunately, that is not a possibility at this time.  You can schedule Daily, but not just working days.  I will open a feature request for this functionality.

Thank you @MKQueen.

Version history
Last update:
‎09-18-2019 09:03 AM
Updated by:
Contributors

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Tags