Execute Sas Code
execute_sas_codeRuns SAS code in a reusable Viya compute session and returns job results, logs, and HTML output. Use fresh_session=True when code must start without inherited SAS state.
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.
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.
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 | |||