Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mv_getjoblog.sas File Reference

Extract the log from a completed SAS Viya Job. More...

Go to the source code of this file.

Detailed Description

Extracts log from a Viya job and writes it out to a fileref

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

Example

First, compile the macros:

filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
%inc mc;

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

filename ft15f001 temp;
parmcards4;
  data ;
    rand=ranuni(0)*1000;
    do x=1 to rand;
      y=rand*4;
      output;
    end;
  run;
  proc sort data=&syslast
    by descending y;
  run;
;;;;
%mv_createwebservice(path=/Public/temp,name=demo)

Execute it:

%mv_jobexecute(path=/Public/temp
  ,name=demo
  ,outds=work.info
)

Wait for it to finish, and grab the uri:

data _null_;
  set work.info;
  if method='GET' and rel='self';
  call symputx('uri',uri);
run;

Finally, fetch the log:

%mv_getjoblog(uri=&uri,outref=mylog)

This macro is used by the mv_jobwaitfor.sas macro, which is generally a more convenient way to wait for the job to finish before fetching the log.

Parameters
[in]access_token_var=The global macro variable to contain the access token
[in]mdebug=set to 1 to enable DEBUG messages
[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]outref=The output fileref to which to APPEND the log (is always appended).
Version
VIYA V.03.04
Author
Allan Bowe, source: https://github.com/sasjs/core

SAS Macros

Definition in file mv_getjoblog.sas.