BookmarkSubscribeRSS Feed
EyalGonen
Lapis Lazuli | Level 10

Hi all,

 

in SAS 9.4 there was an option to take some SAS code and wrap it as a stored process and then invoke it from SAS BI Web Services interactively (invoke API and get back results without calling any other additional API) using REST API.

 

Trying to do the same in SAS Viya 3.5 via the SAS Job Execution Service REST API but it seems from the doc that this API allows only for async job execution whereas I am looking for a synchronized version so that when I invoke the API I get the answer and I do not need to poll and query the API as in the async mode. Is this possible?

 

Eyal

9 REPLIES 9
EyalGonen
Lapis Lazuli | Level 10

Anyone?

 

To be more clear: I am looking for the SAS Viya 3.5 equivalent of SAS 9.4 BI Web Services' option  for invoking the SAS stored process (via REST API) in a synchronous manner. According to the SAS Viya Job Execution REST API that I found it looks like it supports only asynchronous invocation of the Viya job so I am wondering how to achieve my goal in SAS Viya 3.5. Please advise.

BrunoMueller
SAS Super FREQ

I would have a look at the documentation entries:  Executing a Job Simple JSON. To run the jobs, the SASJobExecution is used. It is similar to the SASStoredProcess application in SAS9.

 

If you want to use the REST API I highly recommend to have a lookon  Job object model here https://communities.sas.com/t5/SAS-Communities-Library/SAS-Viya-jobs-object-model-explained/ta-p/633... by @GerryNelson 

 

You might also want to look at https://sasjs.io

 

 

EyalGonen
Lapis Lazuli | Level 10

Hi @BrunoMueller and thanks for replying. I need to invoke the SAS code as a REST API call but it seems from the doc of SAS Job Execution service that it supports only async mode as stated here: https://developer.sas.com/apis/rest/v3.5/Compute/#usage-notes-3 :

 

The Job Execution API is intended to provide a common mechanism for executing and managing asynchronous jobs across environments. 

 

So my question is whether there is another way to accomplish a REST API call that runs SAS code and is synchronous just like was possible in SAS 9.4 BI Web Services?

BrunoMueller
SAS Super FREQ

The API you mentioned does not support synchronous. But as mentioned using the SASJobExecution does this. The URL you call just looks different. You can still provide JSON as input either as a parameter (limited in length) or by using POST and provide JSON in the body of the call.

 

This is an example that calls a job using Proc HTTP and SASJpbExecution it provides some json input using the fileref jsclass 

proc http
  method=post
  url=%tslit(&base_uri/SASJobExecution/?_program=%2FPublic%2Fexample%2Fpost_send_json)
  in=jsclass
  out=resp
  oauth_bearer=sas_services 
  verbose
  /*
   * ask for JSON output
   */
  query=(
    "_OUTPUT_TYPE" = "JSON"
  )
;
headers
  'Content-Type' ='application/json'
;
run;
%put NOTE: &=SYS_PROCHTTP_STATUS_CODE;
%put NOTE: &=SYS_PROCHTTP_STATUS_PHRASE;
%put NOTE: JSON Result;
/* %let rc = %sysfunc(jsonpp(resp, log)); */
joeFurbee
Community Manager

While I was trying to figure out a solution to this, @BrunoMueller came up with something way more efficient than I had. The job execution API is purposely asynchronous due to long running jobs that could/would consume resources. Bruno's use of wrapping the API call in a proc http call is my recommendation as well.


Join us for SAS Community Trivia
SAS Bowl XLIII, The New SAS Developer Portal
Wednesday, August 14, 2024, at 10 a.m. ET | #SASBowl

EyalGonen
Lapis Lazuli | Level 10

 Hi @BrunoMueller @joeFurbee 

 

I will test this suggestion. I am still puzzled as to why the REST API only has an option for async processing. I understand the statement about "long running code" but SAS code does not have to be long running...it can also be short running as in my case 🙂

I would expect the API to support both async and sync processing and to have the calling app decide which API is best suited for the specific call.

 

Eyal

EyalGonen
Lapis Lazuli | Level 10

Hi @BrunoMueller 

 

How do I access the input JSON passed with the "jsclass" fileref (as in your example) in the Job's SAS code?

 

Thanks,

Eyal

BrunoMueller
SAS Super FREQ

You can use the following code:

 

* Reference the uploaded JSON data;
filename indata filesrvc "&_WEBIN_FILEURI";
* Use the JSON engine to provide read-only sequential access to JSON data;
libname indata json;

More details on the macro variables you will find here: https://go.documentation.sas.com/doc/en/pgmsascdc/default/jobexecug/n1btm3vh8xe25en0zcnm3w1sfw2s.htm

AllanBowe
Barite | Level 11

Hi Eyal - we have produced multiple solutions for this issue.  You may wish to take a look at the SASjs Adapter which handles the polling of the Viya Job:  https://adapter.sasjs.io

You could even consider creating your own 'middleware' REST API to call Viya.  We have done this for a client who needed to accept SOAP requests and process them in Viya.  We used NodeJS to convert the request to a Viya call (using SASjs Adapter) and provide the appropriate response.

The library also handles issues such as token authentication and refresh.  It's all MIT open source: https://github.com/sasjs

/Allan
SAS Challenges - SASensei
MacroCore library for app developers
SAS networking events (BeLux, Germany, UK&I)

Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Discussion stats
  • 9 replies
  • 2523 views
  • 4 likes
  • 4 in conversation