Use SAS Viya Copilot for Inline Code Generation
For Statisticians ·
What This Does
SAS Viya Copilot converts a natural-language description into SAS code inside the Viya platform, explains existing code in plain language, and adds inline comments, all inside the same governed, human-in-the-loop environment your organization already validated for SAS work. For a shop that has already invested in SAS Viya (often the case for regulated pharma and CRO work), this is one of the few AI features built specifically for the SAS side of the job rather than adapted from a general-purpose assistant.
Before You Start
- Access to a SAS Viya environment through your organization. Paid plan required, and Viya Copilot is typically included as part of an active SAS Viya license rather than sold separately. Check the current terms on SAS Viya Copilot's product page
- Confirmation from your SAS administrator that Copilot is enabled and approved for your team's environment, since access and governance settings are usually controlled centrally
- Familiarity with where you normally write SAS code inside Viya (SAS Studio, a Viya notebook, or Model Studio), since Copilot's exact entry point sits inside that same workspace rather than as a separate application
- Confirmation from your employer or sponsor that Copilot is on the approved-tools list for project code. SAS macros and programs are frequently proprietary or protocol-specific even when the data behind them is not, and an inline assistant that reads surrounding code sends that context somewhere for processing
Steps
1. Locate Copilot inside your Viya workspace
Look for an assistant icon or a chat-style panel inside your SAS Viya coding environment (SAS Studio or a Viya notebook interface). The exact label and placement can vary by Viya version and by how your administrator has configured the platform, so if the name in this guide does not match what you see, look for anything described as an AI assistant, Copilot, or code helper in the interface, and ask your SAS administrator if you cannot find it.
2. Describe the code you want in plain language
With the assistant panel open, describe the task the way you would explain it to a colleague: "Write a DATA step that merges the demographics and adverse events datasets by subject ID, keeping only subjects with at least one adverse event." Copilot generates the corresponding SAS code, typically inserted into your active program or offered for you to accept.
3. Ask it to explain code you inherited
Paste or open an existing macro with sparse comments and ask Copilot to explain what it does in plain language. This is often faster than tracing PROC and DATA step logic manually, especially for an older macro nobody currently on the team originally wrote.
4. Use it to add inline comments
For a macro or program that needs documentation before a handoff or an audit, ask Copilot to add inline comments explaining each block. Review each one against the actual logic. A comment that misreads a step is worse than no comment at all, since the next reader will trust it.
5. Run every generated step through your normal validation
Nothing here changes your organization's existing process. AI-generated SAS for a regulated deliverable is a first draft, not a finished program. It still needs independent programming or code review, a run against test data with a known answer, and a clean log with no unexpected warnings or notes before it goes anywhere near a submission or a filed report.
Real Example
Scenario: You inherit a legacy macro with a cryptic name and no comments, and need to understand what it does before extending it for a new study.
What you do: Open the macro in your Viya workspace, select the code, and ask Copilot to "explain what this macro does and list its parameters in plain language."
What you get: A plain-language description of the macro's logic and a parameter list, which you check against a small test run to confirm it matches what the macro actually does before you trust the explanation.
Time comparison: Reverse engineering an undocumented macro by reading it line by line: 30-45 minutes for a moderately complex one. Reviewing Copilot's explanation against a test run: 10-15 minutes.
Tips
- Ask for one block or one macro at a time rather than an entire program at once. Shorter requests are easier to verify against a known answer
- If the exact menu name in this guide does not match your version of Viya, describe what you are looking for to your SAS administrator rather than guessing. Viya's interface has changed release to release
- Keep the request itself free of anything protocol-specific your organization would not want outside the validated environment, even when you are confident the surrounding context stays internal to Viya
Tool interfaces change. If a button has moved, look for similar AI/magic/smart options in the same menu area.