BookmarkSubscribeRSS Feed

Code Smarter: AI as a SAS Programming Assistant

Started ‎04-13-2026 by
Modified ‎04-13-2026 by
Views 845

Whether you’re writing your hundredth DATA step, working with inherited code, or debugging a macro that refuses to cooperate, AI coding assistants have become productivity enhancers for programmers. Two of the most capable platforms right now are ChatGPT (from OpenAI) and Claude (from Anthropic). In this post we’ll break down each tool and discuss protecting security, optimizing prompts, enhancing code workflows, and reducing hallucinations.

 

 

Meet the Platforms

 

ChatGPT (OpenAI)

 

ChatGPT handles common SAS tasks well, including DATA steps, standard PROCs, and basic macro questions. It’s widely used and a solid starting point for quick syntax lookups and debugging straightforward code.

 

 

Claude (Anthropic)

 

Claude supports a longer context window, which makes it particularly useful when providing longer programs and files to read before it responds. It gives detailed explanations alongside code, and in my personal opinion, it responds more academically.

 

 

My Preferences

 

I started out using ChatGPT and have since switched over to Claude, upgrading to the monthly paid version. Both have free versions worth trying. The platforms may approach SAS problems differently, and responses vary depending on the prompt. Throughout this post, screenshots from my paid Claude account are included.

 

 

Security First Approach

 

Most public AI platforms use your conversations as training data to improve their models. That means anything you type — variable names, dataset structures, business logic, even the questions you ask — may be retained and used beyond your session. Before using AI for SAS work, ask yourself:

 

  • Does my code reference proprietary datasets, internal table names, or sensitive business logic?
  • Do my variable names or values reveal confidential patient, customer, or financial information?
  • Is there any regulatory reason (HIPAA, FERPA, SOC 2, etc.) this data shouldn't leave my environment?

 

If the answer to any of those is yes, use dummy variable names and fake values instead. Replace real diagnosis codes for placeholders, and describe the structure without exposing the content. You can get equally useful help from AI without sharing anything sensitive.

 

Never submit confidential, proprietary, or regulated data to a public AI platform. When in doubt, anonymize first.

 

 

Prompt Engineering

 

Writing a good prompt is known as “prompt engineering”, essentially how well you describe the problem. Providing context, clearly describing desired output, and breaking down prompts into sub-prompts can greatly enhance the quality of your results.

 

Key things to provide in your prompt:

 

  1. Your SAS environment information (Base SAS 9.4, SAS Viya, version)
  2. The PROC or technique you want to use
  3. Data context such as variable names, types, formats, etc.
  4. Full error messages for the log if debugging
  5. Describe a specific question or desired output

 

For example:

 

“Write SAS code to analyze a SAS dataset” prompts Claude to ask follow up questions, however this leaves a great deal of ambiguity.

 

01_CJC_c1.png

Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.

 

vs.

 

“I’m working with the pg2.np_yearlyTraffic dataset about US national parks. The ParkName variable has park names with a code at the end of the string, for example Big Bend NP. Using the DATA step, how can I create a new variable named Park with only the park name, for example Big Bend? Not all codes have only 2 letters and park names vary in length.” prompts Claude to create code that can be copied and pasted immediately into SAS with a detailed explanation.

 

02_CJC_c2.png

 

03_CJC_c3.png

 

 

Ways AI Speeds Up SAS Coding

 

04_CJC_c4.png

 

 

Hallucinations

 

AI tools can generate code and explanations that look correct, but they are made up—this is called a hallucination. In SAS, some hallucinations to look out for are made up PROC options, options used incorrectly, macros with scope bugs, using SAS date literals in FEDSQL that aren’t supported, or suggesting syntax from the wrong SAS version.

 

How to protect your code:

 

  • Always test AI-generated code in a development environment or on a small subset of data first.
  • Read the SAS log carefully, notes and warnings matter, not just errors.
  • Cross-check unfamiliar options against the official SAS documentation.
  • Ask the AI to explain why the code works—gaps in the explanation may reveal gaps in the code.

 

Think of AI as a partner, and AI generated code as a starting point—not production ready code.

 

 

Final Considerations

 

AI platforms are powerful tools, but they must be approached thoughtfully. The programmers who get the most out of these tools are those who learn to prompt well and know when AI is most helpful for specific tasks. Start small, stay skeptical, and remember it is a partner that still requires human checks.

 

 

Find more articles from SAS Global Enablement and Learning here.

Comments

Thanks for sharing your experience. Keep on exploring for different programming use cases and please publish your conclusions. I would be curious how Claude or GPT fares for code generation versus the SAS Viya Copilot (code assistance).

Contributors
Version history
Last update:
‎04-13-2026 10:33 AM
Updated by:

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore Now →

SAS AI and Machine Learning Courses

The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.

Get started