Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Hands-on 05: (optional) Batch

In the first exercise, you have practiced using SAS Studio to perform interactive program development. Once you are satisfied with the result, you can use a submit the final program in batch, without having to remain connected to the cluster after submitting it. Or you might want to schedule it for unattended submission in production. Let’s see how to do that.

Schedule a Program

  1. In SAS Studio, select the Explorer pane. Navigate to the My Folder shortcut, and right-click on the car-mpg.sas program. Notice that you have multiple choices to schedule your code:

    • Background submit
    • Schedule as a job
    • Deploy as a job

    At a very high level, here is what they do:

    • Background submit is a simple way to run a saved program, once, as a background submission. You can continue to use SAS Studio while it runs - and it keeps running even if you sign out: just come back later to check the result!
    • Schedule as a job creates a copy of your program, and lets you specify how frequently to run the job. You can also specify the time at which the job should run and the start date and the end date for running the job.
    • Deploy as a job creates a copy of your program, and makes it available for an administrator to later decide the scheduling details.
  2. Select Background Submit. SAS Studio briefly shows a confirmation dialog in the lower right of the browser window:

  3. As soon as the confirmation dialog disappears, you can click the Submission button in the lower right of the browser window:

  4. Inspect the Submission Status pane that opens in the lower quadrant of the window. You can find details about the code that you just submitted, such as when it was submitted, when it completed, and so on. After it finishes running, click the name of the job:

  5. In the main window, you can see the copy of the code that has been submitted in background, and explore the execution log and results - just like you did in the interactive environnement.

  6. So far you background submitted your code only once. What if you want the same code to run every day? Let’s schedule it!

    Back in the Explorer pane, navigate to the My Folder shortcut, then right click on the car-mpg.sas program. This time select “Schedule as a job”. A New Trigger window will open. Fill-in your desired schedule, such as in this example, then select Save:

    Compliments, you just scheduled your program!

Batch Submit a Program

  1. In SAS Studio, select the Explorer pane. Navigate to the My Folder shortcut, then right-click on the car-mpg.sas program, and select Download File.

  2. Verify the car-mpg.sas file is in the Downloads folder on your client, and copy it to the /workshop/ folder.

  3. On the desktop, double-click the Student Terminal icon to open a terminal shell.

  4. Use the batch plug-in to the sas-viya command line interface to submit the program from a command line to SAS Viya for batch processing. First, copy and paste the following commands to sign in with the sas-viya command line interface:

    sas-viya --profile Default profile set-endpoint "https://server.demo.sas.com/"
    sas-viya auth login -u Student -p Metadata0
    
  5. Next, copy and paste the following command to submit the car-mpg.sas program:

    sas-viya batch jobs submit-pgm --pgm-path /workshop/car-mpg.sas --context default
    

    Note: The default batch context is predefined in SAS Viya and tailored for the submission of SAS programs.

    You should get a confirmation similar to the following:

    student@server:~$ sas-viya batch jobs submit-pgm --pgm-path /workshop/car-mpg.sas --context default
    >>> The file set "JOB_20240301_041801_511_1" was created.
    >>>   Uploading "car-mpg.sas".
    >>> The job was submitted. ID: "4b188b3c-d62d-425b-8b46-ab6a2adb38e8"  Workload Orchestrator job ID: "111"
    

    You can read in the log that the car-mpg.sas file has been uploaded from your local client to the SAS Viya server, then submitted to run. You are now disconnected from the execution, and you have to explicitly reconnect to retrieve the results at the end.

    Take note of the job ID. You will use it in the next commands.

  6. Copy and paste the following command to verify if the program has completed successfully - be sure to specify the job ID returned in the previous step:

    sas-viya batch jobs list -id "4b188b3c-d62d-425b-8b46-ab6a2adb38e8"
    

    You should get an output similar to the following:

    student@server:~$ sas-viya batch jobs list -id "4b188b3c-d62d-425b-8b46-ab6a2adb38e8"
    ID                                     Name      Workload Job ID   Created By   State       Submitted Time        Started Time          Ended Time            Return Code
    4b188b3c-d62d-425b-8b46-ab6a2adb38e8   car-mpg   111               student      completed   2024-03-01T04:18:02   2024-03-01T04:18:02   2024-03-01T04:18:14   0
    

    Note that the State is completed and the Return Code is a successful 0

  7. You can now retrieve the program results. Copy and paste the following command to download the logs and results to your client:

    sas-viya batch jobs get-results --id  "4b188b3c-d62d-425b-8b46-ab6a2adb38e8"
    

    You should get an output similar to the following:

    student@server:~$ sas-viya batch jobs get-results -id "4b188b3c-d62d-425b-8b46-ab6a2adb38e8"
    ID                                     Name      Workload Job ID   Created By   State       Submitted Time        Started Time          Ended Time            Return Code
    4b188b3c-d62d-425b-8b46-ab6a2adb38e8   car-mpg   111               student      completed   2024-03-01T04:18:02   2024-03-01T04:18:02   2024-03-01T04:18:14   0
    <<<   Downloading the files in the file set to the following path: "./JOB_20240301_041801_511_1".
    <<<   Downloading "car-mpg.log".
    <<<   Downloading "car-mpg.lst".
    <<<   Downloading "car-mpg.sas".
    <<<   Downloading "sasgraph.png".
    

    Note that the logs and results files are download into a newly-created subdirectory on your client. You may remember from the previous exercise in SAS Studio that the code produces a report and a graph: they are now in the car-mpg.lst and in the sasgraph.png files.


Back to top

Copyright © SAS Institute Inc. All Rights Reserved.