Execute Sas Code
execute_sas_codeRun SAS code in a shared Viya compute session and return job results. Preserves WORK tables and macros between calls; pass fresh_session to start clean.
Instructions
Executes the provided SAS code in the Viya environment and returns information about the completed Job. This will create a job definition for the SAS code, execute it, and then retrieve the results.
IMPORTANT — state persists between calls: the code runs in a reusable
compute session that is kept warm and shared across calls (per user),
so SAS state — WORK tables, macro variables, and assigned librefs —
survives between successive execute_sas_code calls. A re-run can
therefore see leftovers from earlier calls (e.g. a check that counts
results twice). Pass fresh_session=True (or call
reset_compute_session) when the code must start from a clean slate.
Limits of the session:
It runs one job at a time. A second call waits until the first ends, so a long job blocks every other call. Run long work with
submit_batch_job, which gets a session of its own, and keep this tool free for short steps. Do not passfresh_sessionwhile another call is still running: it deletes the session under it.Its memory is capped by the deployment's compute pod. A large PROC SQL join or hash object can exhaust it and end the session. For large joins, sort both tables and MERGE them in a DATA step, or do the join in CAS.
Tip: to reach CAS data, prefer libname casuser cas; (or a targeted
caslib statement) over caslib _all_ assign; — on tenants with
many caslibs the latter floods the log with assignment NOTEs.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"sas_code": "<sas_code>"
},
"name": "execute_sas_code"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sas_code | Yes | the SAS code snippet to be executed using the Viya Job Execution API Service | |
| html_results | No | When True (the default), the output is also written as an HTML page, as SAS Data and AI Studio shows it, graphs included, and saved so the person can open it in a browser. The code runs between an ``ods html5`` statement and its close, preceded by ``;*';*";*/;run;quit;`` so that an unterminated statement or quote cannot swallow the close; neither appears in the log. Pass False to submit the code exactly as given. | |
| fresh_session | No | When True, discard any cached compute session first so the code runs with no inherited SAS state (equivalent to calling ``reset_compute_session`` immediately before). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||