Production Ready Macros for SAS Application Developers File Reference

Extract the status from a running SAS Viya job. More...

Go to the source code of this file.

Detailed Description

Extracts the status from a running job and appends it to an output dataset with the following structure:

| uri                                                           | state   | timestamp          |
| /jobExecution/jobs/5cebd840-2063-42c1-be0c-421ec3e1c175/state | running | 15JAN2021:12:35:08 |

To query the running job, you need the URI. Sample code for achieving this is provided below.


First, compile the macros:

filename mc url "";
%inc mc;

Next, create a long running job (in this case, a web service):

filename ft15f001 temp;
  data ;
    do x=1 to rand;
  data _null_;
    call sleep(5,1);

Execute it, grab the uri, and finally, check the job status:


data _null_;
  if method='GET' and rel='state';
  call symputx('uri',uri);


You can run this macro as part of a loop to await the final 'completed' status. The full list of status values is:

  • idle
  • pending
  • running
  • canceled
  • completed
  • failed

If you have one or more jobs that you'd like to wait for completion you can also use the mv_jobwaitfor macro.

[in]access_token_var=The global macro variable to contain the access token
[in]grant_type=valid values:
  • password
  • authorization_code
  • detect - will check if access_token exists, if not will use sas_services if a SASStudioV session else authorization_code. Default option.
  • sas_services - will use oauth_bearer=sas_services.
[in]uri=The uri of the running job for which to fetch the status, in the format /jobExecution/jobs/$UUID/state (unquoted).
[out]outds=The output dataset in which to APPEND the status. Three fields are appended: CHECK_TM, URI and STATE. If the dataset does not exist, it is created.
VIYA V.03.04
Allan Bowe, source:

SAS Macros

Definition in file