Skip to main content
v2026.11,986 entries · CC-BY 4.0

Comment in SAS: * ;, /* */ and %* Macro Comments

How to write a comment in SAS with *, /* */ and %*, which one to use, and how to fix a comment that swallows the rest of your program.

Written and maintained by CASRAI Editorial Board

Published

On this page

In SAS you write a comment in one of two ways: start with an asterisk and end with a semicolon (* message ;), or wrap the text in /* and */. SAS ignores the comment text when it runs the program. Inside the macro language there is a third form, %* message ;, which keeps the comment out of the code the macro generates. The three forms differ in what they may contain, whether they can sit inside a statement, and whether the macro facility still sees what is inside them.

What comments in SAS are used for in research

The SAS Language Dictionary describes the comment as text that SAS ignores, used to document the purpose of a program and to explain unusual segments of code. In research work that is the difference between an analysis another person can audit and a script that only its author can read. A comment can record which variable holds which score, why a record is excluded, or which assumption a procedure call rests on.

The same two constructs also let you switch code off without deleting it. A reviewer or co-author asking why a model was changed is easier to answer when the earlier call is still in the file, commented out, beside a note giving the reason. If you are new to the language, the wider guide to coding in SAS covers the DATA step and procedure structure that these comments sit inside.

The three comment forms at a glance

The data table below sets out the rules for each form, as stated in the SAS documentation. The short version follows here.

  • * message ;: a separate statement of any length that ends at the first semicolon. It cannot contain a semicolon or an unmatched quotation mark inside the text.
  • /* message */: any length, cannot be nested, and may contain semicolons and unmatched quotation marks. It can be written within statements, anywhere a single blank can appear.
  • %* message ;: a macro statement, valid in a macro definition or in open code, that is not stored in the compiled macro.

How to install or access SAS

Comments need no add-on: they are part of the SAS language, so they work in any environment that runs SAS code. For learners and educators who have no licensed copy, SAS offers SAS OnDemand for Academics, a free cloud learning environment. According to SAS, it includes SAS Studio in the browser, needs no local installation, and is open to students, educators and independent learners who create a SAS profile and sign in. SAS lists up to 5 GB of storage and two courses, SAS Programming 1 and Statistics 1. If you already work in a different SAS interface, the SAS Enterprise Guide guide and the guide to SAS for academic use cover the other routes in.

How to comment in SAS step by step

Comment a single line or statement

  1. Type an asterisk at the start of a statement position, then the text.
  2. End the text with a semicolon. The semicolon closes the comment, so the text itself must not contain one.
  3. Check that any quotation marks inside the text are matched, because an unmatched quotation mark is not allowed in this form.

The Language Dictionary’s own example is *This code finds the number in the BY group;. The same page shows a box comment, built from a single comment statement spread over several lines, which is useful for a header at the top of an analysis file:

*---------------------------*
| This uses one comment     |
| statement to draw a box.  |
*---------------------------*;

Comment a block or the end of a line

  1. Type /* where the comment begins.
  2. Write the text. It may run over many lines and may contain semicolons and unmatched quotation marks.
  3. Close it with */.

Because this form may be placed anywhere a single blank can appear, it works inside a statement. The documented example annotates an INPUT statement field by field:

input @1 name $20. /* last name */
      @200 test 8. /* score test */
      @50 age 3.; /* customer age */

It also disables a block of code that contains semicolons, as in the documented example /* For example 1 use: x=abc; for example 2 use: y=ghi; */. A * ... ; comment could not do this, because the first internal semicolon would end it.

Comment out and restore a block in the editor

In the Windows Enhanced Editor, the documentation says that highlighting a block of text and pressing CTRL-/ comments it out, and pressing CTRL-SHIFT-/ uncomments it. This is described for the Enhanced Editor in the SAS 9.2 documentation; other interfaces such as browser-based SAS Studio have their own menus, so use the editor’s own help for the shortcut there.

Comment inside a macro

Inside a macro definition, the Language Dictionary’s tip is to use /* message */ if you want to hide text from the macro facility. The %* message ; form is the macro-language alternative. In both cases the comment is not part of what the macro facility generates, which the next section shows with a worked example.

How to read the output

A comment produces no results and no error, so the place to check it is the SAS log. The macro reference for %* includes an example, called VERDATA, that shows how the three forms behave there. In it, a %* infile given; comment does not appear in the generated code, while /* Jim's data */ and * check data; do appear. The difference is the one to remember:

  • %* comments are macro statements. They are not stored in the compiled macro, so they never reach the log as generated code.
  • /* */ and * ; comments are ordinary SAS text, so they are carried through into the generated code and visible in the log.

A second consequence matters for macro programs. SAS still processes macro statements and macro variable references inside a * message ; comment, so that form cannot hide macro text from the macro facility. If a comment contains something that looks like a macro call, use /* */ or %* instead. The macro reference states that both /*...*/ and %* can hide macro statements from the macro facility.

Illustrative example

This is an illustrative composite, not a program from a real study. It shows the three forms together in a short analysis script:

*Analysis of baseline scores;
/* Exclusion rule agreed with the study team:
   drop records with a missing consent flag; */
data work.clean;
   set work.raw; /* raw extract */
   if consent = . then delete;
run;

%macro report(ds);
   %* the dataset name is passed in as ds;
   proc print data=&ds; run;
%mend;

The first two comments are plain SAS text. The %* comment inside the macro is dropped from the generated code.

Troubleshooting comments in SAS

The rest of the program turned into one big comment

An unmatched /*, an unmatched quotation mark or a missing semicolon can cause SAS to read later code as part of a comment or string. The SAS documentation gives a reset to submit: /* '; * "; */; quit; run;. It is built to close an open block comment, an open comment statement and open quotation marks, followed by QUIT and RUN statements. Submit it, then correct the original error.

An unexpected end of program or session

The Language Dictionary cautions against starting /* in columns 1 and 2. In some operating environments SAS may read it as a request to end the program or session. Indent a block comment so the slash is not in the first two columns.

A semicolon or quotation mark inside the comment text breaks the code

This is the usual consequence of choosing * ; for text that needs a semicolon or an apostrophe. The documentation says that form cannot contain internal semicolons or unmatched quotation marks. Switch to /* */, which allows both. The VERDATA example in the macro reference uses /* Jim's data */ for exactly this reason: the apostrophe is safe in the block form.

Nested block comments

Block comments cannot be nested. If you comment out a section that already contains a /* ... */ comment, the first */ closes the outer comment early. Comment out that section with * ; statements where the text has no semicolons, or remove the inner comment first.

A macro still runs from inside a comment

If a * ... ; comment contains a macro call or a macro variable reference, the macro facility still processes it. Move the text into /* */ or %*.

Free alternatives to SAS

If the goal is a free place to run SAS code, SAS OnDemand for Academics is the route described above. If the goal is to move an analysis to another language, the comment syntax changes. The table below compares what the official documentation of each language says. The comparison of R and SAS covers the wider differences between the two for research analysis.

Option How comments are written Source
SAS OnDemand for Academics Runs SAS code, so * ;, /* */ and %* apply unchanged SAS product page
R Text from a # character to the end of the line is a comment, unless the # is inside a quoted string R Language Definition, 10.2 Comments
Python A comment starts with a # that is not part of a string literal and ends at the end of the physical line Python Language Reference, 2.1.3 Comments

Neither R nor Python has a slash-asterisk block form in the passages cited above: a multi-line note is written as a run of # lines. When porting a SAS script, the practical change is that every /* */ block becomes a series of # lines. For a SAS-specific walk-through of a common first task, see the guide to PROC IMPORT in SAS.

Sources

Data: SAS comment forms compared by documented rules

Compares the three SAS comment forms (comment statement, block comment, macro comment) on the rules the SAS Language Dictionary and SAS Macro Language Reference state: how each ends, whether it may contain semicolons or unmatched quotation marks, whether it can nest, whether it can sit inside a statement and whether it hides text from the macro facility. Compiled by reading both reference pages.

SAS comment forms compared by documented rules
Comment formEnds withMay contain semicolonsMay contain unmatched quotation marksCan be nestedHides macro text from the macro facilityAppears in generated code (VERDATA example)
* message ;SemicolonNoNoNot statedNoYes
/* message */*/YesYesNoYesYes
%* message ;SemicolonNo, unless quotedNo, quotes must matchNot statedYesNo

Sources

Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · full access

Ask about Comment in SAS: * ;, /* */ and %* Macro Comments

Full access: large monthly usage, up to 10 source passages behind each answer, and MCP and API access for Claude Code, Codex and other CLIs. Cancel any time.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →