How to Comment Your Code for Future You (and Your Team)

As data analysts, we often focus on solving the problem in front of us—cleaning the data, building a model, or producing that final report. But have you ever opened your old SAS code and had no idea what you were thinking? You’re not alone. Documenting your code is one of the most undervalued (yet critical) habits for long-term productivity and team collaboration.
Let’s walk through practical ways to document your SAS code effectively—so that 3-months-from-now you (or your teammates) can pick it up with zero confusion.
Why Bother with Documentation?
- You’ll save hours when revisiting old projects.
- Team members can understand, reuse, and build on your work.
- You reduce errors and rework caused by ambiguous code.
- It’s a huge win when onboarding new analysts or handing off work.
How to Comment Your Code in SAS: Best Practices + Examples
1. Use Clear Section Headers
Break your code into logical sections with comments as signposts.

2. Comment Why, Not Just What
It’s tempting to say what the code is doing—but what’s more useful is why you’re doing it. This gives your future self (and team members) the context behind the decision.

3. Describe Key Variables
When working with datasets, document important variables and any transformations you make.

Even better, include a quick variable dictionary at the top of your code or in a separate README:

4. Explain Complex Logic or Business Rules
If your analysis includes tricky conditions or business-specific logic, add inline comments.

This saves your team from guessing what “>2” means or why the 6-month window was chosen.
5. Create a Summary at the Top
For longer projects, start your program with a short summary block. This helps you or someone else understand the purpose of the script without reading every line.

6. Use Meaningful Names for Datasets and Variables
Avoid generic names like data1
or temp2
. Make your names descriptive.

Develop Your Own Commenting Style
As you get more comfortable documenting your SAS code, you’ll naturally develop your own commenting style—and that’s a good thing. Maybe you like writing short summaries before each data step, or perhaps you prefer inline comments next to critical lines of logic.
What matters most is consistency and clarity—both for yourself and anyone else reading your code. Over time, your comment style becomes part of your analytical voice, and it can make your work more approachable and professional.
Final Thoughts
Writing clean, well-documented SAS code isn’t just polite—it’s professional. It makes your work reusable, understandable, and trustworthy. Future you (and your team) will thank you.
Start small: add a project header, explain one business rule, or describe a derived variable. Over time, good documentation becomes second nature—and a massive asset to your career.