Skip to main content
Glama
SAS MCP Server

SAS MCP Server

Official
by sassoftware

Execute Sas Code

execute_sas_code
Destructive

Run 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 pass fresh_session while 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

NameRequiredDescriptionDefault
sas_codeYesthe SAS code snippet to be executed using the Viya Job Execution API Service
html_resultsNoWhen 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_sessionNoWhen 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

NameRequiredDescriptionDefault

No arguments

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv1.18.0
    • addedInput schema / properties / html_results
      Added value: +{
      +  "default": true,
      +  "description": "When True (the default), the output is also written\nas an HTML page, as SAS Data and AI Studio shows it, graphs\nincluded, and\nsaved so the person can open it in a browser. The code runs\nbetween an ``ods html5`` statement and its close, preceded by\n``;*';*\";*/;run;quit;`` so that an unterminated statement or\nquote cannot swallow the close; neither appears in the log.\nPass False to submit the code exactly as given.",
      +  "type": "boolean"
      +}
  2. Changed1 schema field changedv1.7.0
    • addedInput schema / properties / fresh_session
      Added value: +{
      +  "default": false,
      +  "description": "When True, discard any cached compute session first\nso the code runs with no inherited SAS state (equivalent to\ncalling ``reset_compute_session`` immediately before).",
      +  "type": "boolean"
      +}
  3. Changed1 schema field changedv1.2.0
    • changedOutput schema / (root)
      Previous value: -nullNew value: +{
      +  "additionalProperties": {
      +    "type": "string"
      +  },
      +  "type": "object"
      +}
  4. First observedv0.1.0

TDQS

A4.6/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description discloses behavior well beyond the annotations: a warm reusable per-user session, persisting WORK tables, macro variables and librefs, one-job-at-a-time serialization, and memory caps that can kill the session. It even warns that fresh_session can delete a session underneath a concurrent call. It stops short of describing error/failure semantics or log contents, but this is unusually rich disclosure for a destructive, open-world tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Purpose is front-loaded, followed by a prominent IMPORTANT state-persistence block and a bulleted limits section, so an agent can skim to what matters. It is longer than typical but nearly every sentence carries a distinct constraint; the CAS libname tip is the one item that sits slightly outside the core contract.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

An output schema exists, so return values need not be explained, and the description covers what the schema cannot: state inheritance across calls, concurrency limits, session memory ceilings, and the correct sibling for heavy work. Nothing an agent needs to invoke this safely appears to be missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the schema already defines all three parameters, giving a baseline of 3. The description still adds operational meaning for fresh_session — that it must not be used while another call is running because it deletes the session, and that it is equivalent to reset_compute_session. The html_results parameter is left to the schema, which is acceptable given its thorough description there.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The opening sentence names a specific verb and resource ('Executes the provided SAS code in the Viya environment') and then spells out the underlying lifecycle: create a job definition, execute it, retrieve the results. It is clearly distinguishable from submit_batch_job (long work) and reset_compute_session (state reset), which are explicitly named.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It gives explicit when-to-use ('keep this tool free for short steps'), when-to-use-something-else ('Run long work with submit_batch_job, which gets a session of its own'), and when-not-to-pass-a-parameter ('Do not pass fresh_session while another call is still running'). The CAS/libname tip adds a concrete recommended pattern rather than leaving it to inference.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Deploy Server

Other Tools