SAS Viya Copilot for Code Assistance in SAS Data and AI Studio
Recent Library Articles
In this post, we’ll take a look at how SAS Viya Copilot for Code Assistance can help with some of those everyday tasks: understanding code, improving it, and making changes more confidently—all without leaving the SAS Data and AI Studio environment.
Already a SAS Viya user? Then you know you’ve got a wealth of capabilities at your fingertips. We’ll explore those together, giving you access to all the insights you’ll need. Join us on December 10 at 11 a.m. ET.
December 1: An AI elf that converts SAS code - tests it on SAS Viya - and opens its own pull requests
Claude or GitHub Copilot, the SAS Viya MCP Server, the GitHub MCP server and a few strict rules: a generic setup that lets an agent work autonomously on a SAS migration repository without losing sleep. By Ole-Martin Hafslund, Principal Pre-Sales Technical Architect, SAS Norway, SASJuletip #1 - Juletip2026
Figure 1. Juletip 2026 - agentic SAS code conversion. Illustration generated with Microsoft Copilot. From autocomplete to colleague
Code completion is nice. What we really want is an agent that takes a work package, converts the SAS code, runs the tests, documents what it changed and opens a pull request - while we review rather than type.
Figure 2. What the setup does: from analysis to tested, documented code. Failed tests loop back to the LLM step; the LLM is replaceable, the controls and evidence stay the same. The cool feature: autonomy with a rulebook
The trick is not the model. It is the framework around it. The agent works inside a small set of files in the repository that define what it may and may not do:
File / mechanism
Purpose
Instructions and skills
How to convert SAS 9 code, coding standards, when to stop
Allowlist
Which repository, owner and branches the agent may push to
Actor-based branches
Each developer and agent works on its own branch prefix, so multiple people can share one repository
Hooks
Secret scan and tests run before any commit or push
BLOCKED.json
When the agent hits a decision reserved for humans, it writes the reason here and stops
GitHub Actions
The same checks run again on the pull request; a human approves the merge
Under the hood there are several layers of control, and no single one carries the risk on its own. The model can be clever; the system is what makes it safe.
Figure 3. Layers of control: identity, workstation policy, tool boundary, environment boundary, human review and promotion.
A conversion the agent can do on its own
All examples use SASHELP.CARS, so you can run them on any SAS installation. Here is classic SAS 9 summarisation code - average list price per make and origin, for makes with more than ten models:
SAS 9 (PROC SQL)
proc sql;
create table work.top_makes as
select make, origin,
count(*) as models,
mean(msrp) as avg_msrp format=dollar10.
from sashelp.cars
group by make, origin
having calculated models > 10
order by avg_msrp desc;
quit;
The agent's proposal for SAS Viya, running in CAS:
SAS Viya (CAS, PROC FEDSQL)
cas mysess;
caslib _all_ assign;
/* Load the input once into CAS */
proc casutil;
load data=sashelp.cars outcaslib="casuser" casout="cars" replace;
quit;
proc fedsql sessref=mysess;
create table casuser.top_makes {options replace=true} as
select make, origin,
count(*) as models,
avg(msrp) as avg_msrp
from casuser.cars
group by make, origin
having count(*) > 10;
quit;
/* CAS tables have no order: sort and format when you read the result */
proc print data=casuser.top_makes;
format avg_msrp dollar10.;
run;
cas mysess terminate;
The details the agent has to get right:
CALCULATED does not exist in FedSQL. The aggregate is repeated in HAVING.
MEAN becomes AVG. FedSQL uses the ANSI aggregate name.
ORDER BY and FORMAT= move out of the CREATE. A CAS table is distributed and has no row order, so sorting and formatting happen when the result is read.
The table is replaced explicitly. The replace=true option makes the step re-runnable.
Those rules live in the skill file, so the agent learns them once and applies them everywhere. Bonus: the same code, pushed down to SingleStore
If your SAS Viya platform includes SingleStore (SAS SpeedyStore), the agent can also convert SAS code into SingleStore SQL, so the heavy lifting runs in the database and only the result comes back to SAS. Same example, with explicit SQL pass-through:
SAS Viya + SingleStore (explicit pass-through)
libname s2 singlestore server="&S2_HOST" port=3306 database=proj_analysis
user="&S2_USER" password="%sysget(S2_PWD)";
/* One-time load of the example data */
data s2.cars;
set sashelp.cars;
run;
proc sql;
connect using s2;
/* runs entirely inside SingleStore */
execute (
create table top_makes as
select make, origin,
count(*) as models,
avg(msrp) as avg_msrp
from cars
group by make, origin
having count(*) > 10
) by s2;
/* only the small result travels back to SAS */
create table work.top_makes as
select * from connection to s2
(select * from top_makes order by avg_msrp desc);
disconnect from s2;
quit;
Typical conversions the agent applies when SAS logic moves into SingleStore SQL:
SAS
SingleStore SQL
Note
calculated x
repeat the expression
same as FedSQL
mean(x)
avg(x)
ANSI name
'01JAN2025'd
'2025-01-01'
ISO date literal
intnx('month', d, 1)
date_add(d, interval 1 month)
check the alignment argument of INTNX
intck('day', d1, d2)
datediff(d2, d1)
argument order differs
put(x, 8.) / input(s, 8.)
cast(x as char) / cast(s as double)
formats do not exist in the database
x < 5 with missing x
x < 5 or x is null
SAS treats missing as the smallest value; SQL NULL is never < 5
Look out for the other juletip Table design, data types from SAS to SingleStore, users and grants, collation and the SingleStore MCP server are covered in depth in my other Juletip 2026 post: Getting started with SingleStore from SAS - an agent-assisted approach. This post stays with the conversion loop.
Where MCP comes in
An agent without tools can only write text. With MCP (Model Context Protocol) servers connected, it can act - and every action goes through a server that you can restrict, log and review. Three servers do the work in this setup:
Figure 4. One agent, three MCP servers. Each has its own job and its own permissions. The SingleStore MCP server is described in the separate SingleStore juletip.
MCP server
What the agent uses it for
Keep it safe by
SAS Viya MCP Server
Submit SAS code to a TEST environment, read the log, list caslibs, tables and columns
pointing it at TEST only; every call runs under your own SAS Viya identity
GitHub MCP server
Read the work package (issue), create a branch, push files, open the pull request, read the Actions result, comment
a fine-grained token scoped to one repository, branch protection on main, read-only toolsets where writing is not needed
SingleStore MCP server
Read tables, DDL, grants and query plans when the code pushes down to SingleStore
read-only tools; DDL changes go to approval (see the SingleStore juletip later in December)
With these in place the agent can submit the converted code to SAS Viya TEST, read the log and compare the output with the SAS 9 result. Failed comparison? It fixes the code and tries again, inside a bounded loop. Still failing after the limit? It writes BLOCKED.json and asks for help.
Figure 5. The bounded loop. Mismatch goes back to Convert; the limit sends it to a human.
The loop
loop:
read work package (GitHub issue) -> GitHub MCP
convert -> submit to TEST -> read log -> SAS Viya MCP
compare output with baseline
if match: push branch, open PR -> GitHub MCP
if attempts > limit: write BLOCKED.json, stop
The GitHub MCP server: the agent's hands in the repository
Git commands in a terminal work, but the GitHub MCP server gives the agent structured, permission-checked access to everything around the code: issues, pull requests, reviews and Actions. GitHub hosts a remote version, so there is nothing to install. Its tools are grouped in toolsets, and adding /readonly to the URL removes every write tool.
.vscode/mcp.json (GitHub Copilot, Agent mode - signs in with OAuth)
{
"servers": {
"github": {
"type": "http",
"url": "https://api.githubcopilot.com/mcp/"
},
"github-actions-readonly": {
"type": "http",
"url": "https://api.githubcopilot.com/mcp/x/actions/readonly"
}
}
}
Claude Code CLI
claude mcp add --transport http github https://api.githubcopilot.com/mcp/ \
-H "Authorization: Bearer $GITHUB_PAT" # fine-grained token, one repository
$GITHUB_PAT = your persona access token in github.
What the agent does with it, in this setup:
Pick up the work. Each SAS program to convert is a GitHub issue with the program path and the baseline. The agent reads the issue instead of a chat message, so the request is traceable.
Work on its own branch. It creates a branch with its actor prefix and pushes the converted code, the change log line and the test evidence.
Open the pull request. The PR description summarises what changed and why, and links back to the issue.
Read the checks. It reads the GitHub Actions result for its own PR. Red? It fixes and pushes again - within the attempt limit.
Leave the merge to a human. Branch protection on main requires a human review. The agent can comment, never merge.
Juletip Give each agent role the smallest toolset it needs. A review agent that only reads pull requests and Actions logs can use the read-only endpoints, so it cannot change anything even if a prompt tells it to.
Figure 6. Daily workflow for one SAS program: agent, LLM, MCP server, SAS Viya TEST and the Git platform. Promotion to production follows the normal release process, without AI access.
Functional demo: give your own elf a rulebook
Everything below is copy-paste ready. You need a SAS Viya test environment you are allowed to use, VS Code with GitHub Copilot or the Claude Code CLI, and a GitHub repository with one SAS 9 program and its baseline output.
Step 1 - start the SAS Viya MCP Server
Terminal
git clone https://github.com/sassoftware/sas-mcp-server.git
cd sas-mcp-server
uv sync
cp .env.sample .env # set VIYA_ENDPOINT=https://your-viya-test-server
uv run app # serves http://localhost:8134/mcp, sign-in via SAS Logon (OAuth PKCE)
The SAS Viya side needs a little SAS Logon configuration first; the SAS Communities post in the references walks through it step by step. The tool list grows quickly between releases, so check the README for the version you run.
Step 2 - connect your agent to SAS Viya and GitHub
.vscode/mcp.json (GitHub Copilot, Agent mode)
{
"servers": {
"sas-viya": { "type": "http", "url": "http://localhost:8134/mcp" },
"github": { "type": "http", "url": "https://api.githubcopilot.com/mcp/" }
}
}
Claude Code CLI
claude mcp add --transport http sas-viya http://localhost:8134/mcp
claude mcp add --transport http github https://api.githubcopilot.com/mcp/ \
-H "Authorization: Bearer $GITHUB_PAT"
claude mcp list # then authenticate sas-viya inside Claude Code
Juletip If GitHub Copilot answers that the model you asked for is not available and it is using "auto" instead, it is not your config. Model availability depends on your Copilot plan and your organisation's model policy. The same applies to MCP: in Copilot Business and Enterprise, the "MCP servers in Copilot" policy must be enabled.
Step 3 - the skill file
Put this where your agent loads skills - for example .claude/skills/sas9-to-viya-conversion/SKILL.md for Claude Code, or the skills folder your GitHub Copilot setup uses. Only the name and description are loaded up front; the body is read when the task matches.
SKILL.md
---
name: sas9-to-viya-conversion
description: Convert one SAS 9 program to run on SAS Viya, test it in the TEST environment through the SAS Viya MCP Server, compare it with the SAS 9 baseline, open a pull request through the GitHub MCP server, and stop when a human decision is needed.
---
# SAS 9 to SAS Viya conversion
## Before you write code
Discover before you operate: list the libraries or caslibs, tables and columns you need. Never guess a name.
Read the SAS 9 baseline for this program (row counts, totals, log) from baseline/.
## While converting
Show the code before you run it. Run only in the TEST environment.
FedSQL has no CALCULATED keyword: repeat the expression in HAVING and WHERE. Use AVG, not MEAN.
CAS tables have no row order: sort when you read the result, not when you create it.
Replace hard-coded paths with the project path macro variables. Never invent a path.
Keep business logic identical. If you think the logic is wrong, say so - do not fix it silently.
## Definition of done
The log has zero ERROR lines and no new WARNING lines.
%baseline_check reports BASELINE MATCH for every output table.
CHANGELOG.md has one line describing the change, and a pull request is open from your own branch.
## When to stop
Maximum 3 attempts per program. Then write .agent/session/BLOCKED.json with the reason and stop.
Never push to main, never merge, never change the allowlist, never commit secrets, customer data or generated outputs.
Step 4 - the referee: a baseline check in SAS
The agent must not be the judge of its own work. This macro is. Run it as is in SAS Studio to see it catch a one-dollar difference for one make in SASHELP.CARS; in your project, point it at the SAS 9 baseline and the converted output (copy CAS tables to WORK first).
baseline_check.sas
/* baseline_check.sas - does the converted result match the SAS 9 baseline? */
%macro baseline_check(base=, compare=, id=);
proc sort data=&base out=work._bc_base; by &id; run;
proc sort data=&compare out=work._bc_cmp; by &id; run;
proc compare base=work._bc_base compare=work._bc_cmp noprint
criterion=1e-9 method=relative;
id &id;
run;
%let _rc=&sysinfo;
%if &_rc = 0 %then %put NOTE: BASELINE MATCH - &compare equals &base..;
%else %put ERROR: BASELINE MISMATCH (SYSINFO=&_rc) - &compare differs from &base..;
proc datasets lib=work nolist; delete _bc_base _bc_cmp; quit;
%mend baseline_check;
/* Try it with SASHELP.CARS: one tiny difference is enough to fail */
proc sql;
create table work.sas9_baseline as
select make, origin, count(*) as models, mean(msrp) as avg_msrp
from sashelp.cars group by make, origin;
quit;
data work.converted_result;
set work.sas9_baseline;
if make = 'Audi' then avg_msrp = avg_msrp + 1;
run;
%baseline_check(base=work.sas9_baseline, compare=work.converted_result, id=make origin)
Step 5 - the stop sign
When the loop runs out of attempts, the agent writes this file and stops. Your CI can refuse to merge while it exists, and a human picks it up in the morning:
.agent/session/BLOCKED.json
{
"status": "blocked",
"program": "programs/top_makes.sas",
"attempts": 3,
"reason": "Baseline mismatch on avg_msrp after conversion (rounding differs in the 10th decimal).",
"needs": "Human decision: accept the tolerance or keep the step in SAS Compute.",
"next_safe_step": "none - waiting for a human"
}
Step 6 - the prompt
Prompt
Pick up issue #1 with the sas9-to-viya-conversion skill (programs/top_makes.sas).
Discover the tables first. Show me the converted code before running it.
Run it in TEST through the sas-viya MCP server, read the log, run
%baseline_check against baseline/top_makes, and if the baseline matches,
push your own branch and open a pull request through the github MCP server
that links to the issue. Then report the result of the GitHub Actions checks.
Expected behaviour: the agent reads the issue, lists the caslib and columns, shows the FedSQL, asks before it submits, summarises the log, reports BASELINE MATCH or the mismatch, and either opens a pull request or writes BLOCKED.json. If it ever tries to push to main, branch protection says no - which is exactly the point.
What we learn
Rules beat prompts. A clear allowlist and stop conditions do more for safety than any clever prompt.
One MCP server per job. SAS Viya for running code, GitHub for the repository, SingleStore for the database - each with its own, smallest possible permissions.
Humans own the irreversible steps. Merging to main, changing the allowlist and anything in production stay manual.
Make it multi-developer from day one. Actor-based branches and ownership rules avoid agents overwriting each other.
The baseline is the boss. Counts, totals and logs from SAS 9 decide whether a conversion is done - not the agent's confidence.
Test environments and synthetic or sample data only. Production is never touched by AI; promotion goes through the normal change management.
References
SAS 9 and SAS Viya
SAS Viya MCP Server (sassoftware/sas-mcp-server)
Connecting GitHub Copilot to SAS Viya with the SAS Viya MCP Server (SAS Communities)
Connecting Claude Code CLI to SAS Viya with the SAS Viya MCP Server (SAS Communities)
SAS Viya: FedSQL Programming for SAS Cloud Analytic Services
SAS/ACCESS Interface to SingleStore: SQL pass-through and data types
SAS Programmer's Guide: Missing Values
GitHub and agents
GitHub MCP server (github/github-mcp-server)
GitHub MCP server: remote server and toolsets
GitHub Docs: Setting up the GitHub MCP Server
VS Code: Add and use MCP servers
Claude Code documentation
Model Context Protocol - documentation
SingleStore
SingleStore MCP server (singlestore-labs/mcp-server-singlestore)
My other Juletip 2026 post: Getting started with SingleStore from SAS - an agent-assisted approach
Happy Advent all SAS Lovers out there
... View more
I am a beginner training a small neural network and I am watching the training loss and the validation loss as it learns. At first both losses go down together but after a while the training loss keeps failing while validation loss starts to rise again. I have read that this is a sign of overfitting, but I am not sure I really understand what is happening inside the model. Why would the model keep getting better on the training data while getting worse on new data? What should I do when I see this pattern — stop training, change something about the model, or get more data?
... View more
I am modelling student enrollments by school district statewide using random coefficients negative binomial regression. My current data set spans ten years (2016 through 2025) which has the COVID disruption right in the middle, so I added a switching regime component to the model to account for the dramatic drop in enrollment statewide in fiscal year 2021, which is fitfully recovering in the most recent five years (the data disruption most likely due to reporting issues with school districts). Recalling the Quant citation from econometrics ("Test of the Hypothesis That a Linear Regression System Obeys Two Separate Regimes, JASA Vo. 55, pp. 324-330, 1960) I want to test the null hypothesis that the error variance is constant between regimes (pre and post COVID) in PROC GLIMMIX so I will know if it is statistically sound to run one switching regime regression model or if I need to model each regime separately. I had no luck looking for guidance or examples involving PROC GLIMMIX, so any assistance with this will be greatly appreciated!
... View more
Yes, I know. This was supposed to be a four-part series. I lied. Well, not really. Although not part of the original plan, at some point along the way, I came up with the idea to extend the series by adding a comparison of results of all the feature extraction methods I covered. In this series, I’ve covered four methods to create new features using SAS Model Studio. In Part 1, I covered Principal Components Analysis (PCA), Part 2 introduced Robust PCA, Part 3 was on Autoencoders, and Part 4 covered Singular Value Decomposition (SVD). If you’re just joining this party now, you’ll probably want to check out those posts before reading this one. What fun would it be start at the end of the story?
The main purpose of the series was to introduce feature extraction, also called feature engineering, methods that are available in SAS Model Studio. Each post introduced a different method, provided some background and, when appropriate, mathematical details of the method, and a data example of how to implement the method and consume the results provided in Model Studio. The purpose of this post is to pull those examples together and compare the results. I’ll actually be covering two examples here.
... View more