• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / SAS / SAS Comments – Commenting Your SAS Code the Right Way

SAS Comments – Commenting Your SAS Code the Right Way

January 19, 2022 Leave a Comment

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: http://theprogrammingexpert.com/sas-comments/;
*Author: The Programming Expert;

/* The multiline comment way:
This is a article about SAS comments
URL: http://theprogrammingexpert.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: http://theprogrammingexpert.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.

Other Articles You'll Also Like:

  • 1.  Change Length of Character Variable in SAS Dataset
  • 2.  SAS Not Equal – Check if a Variable is Not Equal to Another in Data Step
  • 3.  Multiple Condition If Statements in SAS Macro Language
  • 4.  Get Substring from Right in SAS
  • 5.  SAS Remove Formats from Dataset with PROC DATASETS
  • 6.  Round Number to 2 Decimal Places in SAS
  • 7.  SAS intnx – Add or Subtract Time from Date Variables in SAS Data Step
  • 8.  SAS compress – Remove Whitespace and Characters from String
  • 9.  SAS calculated – Use Columns Created from Select in PROC SQL
  • 10.  SAS max() Function – Find Maximum Value Across Columns in Data Step

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy

x