For those of you coming from SAS 9, Stored Processes were the way to go for executing defined SAS code to bind a web application with a SAS environment. While it was possible to achieve the same using SAS Viya Jobs in SAS Viya or calling Compute Server REST APIs, the approach was not perfect due the asynchronous nature of SAS Viya. With 2025.09 stable release, SAS Viya introduces an alternative directly targeted to web developers or developers executing synchronously.
Compute Tasks in SAS Viya provide a fast, lightweight way to execute short SAS programs via a single HTTP request. Unlike the Job Execution Service (JES), which is asynchronous and resilient, Compute Tasks are synchronous and optimized for speed, making them ideal for quick, cancelable, and restartable jobs.
Field | Type | Description |
name | string | Name of the task |
description | string | Description of the task |
code | string | SAS program to execute |
arguments | map[string]string | Key-value pairs for variables and execution opts |
Example:
{
"name": "My Task",
"description": "This is my task",
"code": "data _null_; run;",
"arguments": {
"_contextName": "ReusableContext"
}
}
Field | Type | Description |
name | string | Name of the task |
id | string | Task ID |
description | string | Description of the task |
state | string | State of the job (e.g., completed) |
jobConditionCode | int | Exit code of the job |
creationTimeStamp | time.Time | When the task was executed |
elapsedTime | int64 | Time to execute (ms) |
contextId | string | Context ID used |
contextName | string | Context name used |
sessionId | string | Session ID used |
jobId | string | Job ID |
error | object | Error details, if any |
variables | map[string]string | Final values of requested variables |
SAS Program:
data _null_;
call sleep(1, 10);
TaskRequest:
{
"name": "Get Exit Code",
"description": "A task that sleeps for 10 seconds.",
"code": "data _null_; call sleep(1, 10); run;",
"arguments": {
"_contextName": "ReusableContext",
"_omitJsonLog": "true",
"_omitTextLog": "true",
"_omitJsonListing": "true",
"_omitTextListing": "true"
}
}
HTTP Request:
Response:
{
"id": "...",
"name": "Get Exit Code",
"state": "completed",
"jobConditionCode": 0,
...
}
SAS Program:
%global MYNAME;
data _null_;
file _webout;
put '<!DOCTYPE html>';
put '<html lang="en">';
put '<head><title>Hello World!</title></head>';
put '<body role="main">';
put "<h1>Hello %sysfunc(htmlencode(&MYNAME))!</h1>";
put '</body>';
put '</html>';
run;
TaskRequest:
{
"name": "Hello World",
"description": "A hello world program that writes an html file to _webout.",
"code": "...", // (see above)
"arguments": {
"_contextName": "ReusableContext",
"_addJesBeginEndMacros": "true",
"_OUTPUT_TYPE": "html",
"_omitTextLog": "true",
"_omitSessionResults": "false",
"_resultFilter": "eq(name,'_webout')",
"MYNAME": "World"
}
}
Response:
Multipart with:
SAS Program:
proc import datafile=&_WEBIN_FILEREF
dbms=csv
out=work.mydata
replace;
getnames=yes;
run;
proc print data=work.mydata;
run;
Multipart Request:
TaskRequest:
{
"name": "Print CSV File from Multipart Request",
"description": "A task that prints the contents of a csv file.",
"code": "...", // (see above)
"arguments": {
"_contextName": "ReusableContext",
"_variableFilter": "contains(name,'_WEBIN_FILEREF')",
"_omitJsonLog": "true",
"_omitTextLog": "true"
}
}
Response: Multipart with:
SAS Compute Tasks offer an alternative to SAS Viya Jobs or direct API calls to the Compute Server endpoints. It makes it really easy to execute SAS code in a single synchronous call. This is ideal for example when you want to build a web interface and populate prompts with data, or when retrieving data stored in SAS or in a database using SAS code. The real benefits comes with code that executes in a short amount of time. This is the reason why it fits nicely in the web development world. With the REST APIs for the Compute server and CAS, the SAS Viya Jobs and the Compute Tasks, you are armed to design responsive web applications in no time.
I will most probably write some sample web applications using the Compute Tasks. If you have ideas or topics that you would like to see covered, please don't hesitate to comment this article.
Find more articles from SAS Global Enablement and Learning here.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.