mv_getjobresult.sas File Reference

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

Go to the source code of this file.

Detailed Description

Extracts result from a Viya job and writes it out to a fileref and/or a JSON-engine library.

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 test;
    rand=ranuni(0)*1000;
    do x=1 to rand;
      y=rand*4;
      output;
    end;
  run;
  proc sort data=&syslast
    by descending y;
  run;
  %webout(OPEN)
  %webout(OBJ, test)
  %webout(CLOSE)
;;;;
%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 result (In this case, WEBOUT):

%mv_getjobresult(uri=&uri,result=WEBOUT_JSON,outref=myweb,outlib=myweblib)
Parameters
[in]access_token_var=The global macro variable containing 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 (unquoted).
[out]result=(WEBOUT_JSON) The result type to capture. Resolves to "_[column name]" from the results table when parsed with the JSON libname engine. Example values:
  • WEBOUT_JSON
  • WEBOUT_TXT
[out]outref=(0) The output fileref to which to write the results
[out]outlib=(0) The output library to which to assign the results (assumes the data is in JSON format)
Version
VIYA V.03.05
Author
Allan Bowe, source: https://github.com/sasjs/core

SAS Macros

Definition in file mv_getjobresult.sas.