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.
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 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.
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.
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:
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.
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:
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.
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.
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:
Think of AI as a partner, and AI generated code as a starting point—not production ready code.
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.
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).
Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.
Explore Now →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.