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;
data work.info;
  set work.info;
  where method='GET' and rel='state';
run;
%mv_jobwaitfor(ALL,inds=work.info,outds=work.jobstates)

%* and grab the uri;
data _null_;
  set work.jobstates;
  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.

If the remote session calls endsas then it is not possible to get the log from the provided uri, and so the log from the parent session is fetched instead. This happens for a 400 response, eg below:

ErrorResponse[version=2,status=400,err=5113,id=,message=The session
requested is currently in a failed or stopped state.,detail=[path:
/compute/sessions/LONGURI-ses0006/jobs/LONGURI/log/content, traceId: 63
51aa617d01fd2b],remediation=Correct the errors in the session request,
and create a new session.,targetUri=<null>,errors=[],links=[]]
Parameters
[in]access_token_var=The global macro variable to contain the access token
[in]mdebug=(0) 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 (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.