When writing programs in any programming language, comments can be useful to add further context to the code. In SAS, there are a few ways you can comment code in your programs.
*This is a comment;
%*This is a second comment;
/*This is a third comment*/
/*This is a fourth multi-line
comment*/
There are three main ways you can add comments to your SAS code.
The first is to start with an asterisk and end with a semicolon.
*This is a comment;
The second way to add SAS comments is to start with an percent sign and asterisk, and end with a semicolon.
%*This is a comment;
The last way is to start with a forward slash and asterisk and end with an asterisk and forward slash.
/*This is a comment*/
How to Create Multiline Comments in SAS
Many times when we are programming, it is not enough just to add a single line comment to explain or describe what is going on in the code.
For example, when creating a file, best practices are that we should add a header which may include filename, date, author, description, etc.
In this case, you could use single line comments for each line, but something more useful is to use multiline comments in SAS with the /* */ way of creating a SAS comment.
Below are two ways you can do multiline commenting in your SAS code.
*The single line comment way:;
*This is a article about SAS comments;
*URL: https://daztech.com/sas-comments/;
*Author: The Programming Expert;
/* The multiline comment way:
This is a article about SAS comments
URL: https://daztech.com/sas-comments/
Author: The Programming Expert */
One trick is to use Ctrl-/ to comment out multiple lines of code in your SAS program. Just highlight what you want to comment out, and then press Ctrl-/.
If you were to type out your comments and then use Ctrl-/, the resulting SAS comment would look like:
/* The multiline comment way: */
/* This is a article about SAS comments */
/* URL: https://daztech.com/sas-comments/ */
/* Author: The Programming Expert */
Personally, I prefer to only use the second way in all of my SAS comments, but that is just personal preference. In my experience, it’s easier to toggle with Ctrl-/ than to worry about * and ;.
Hopefully this article has been useful for you to understand how to add comments to your SAS code.