execute_sas_code
Execute SAS code in Viya, retrieve results with logs and output, and persist state across calls via a reusable compute session.
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 | |
| 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 | |||