There are three types of comments: PL/1 style, asterisk style, and macro style.
/* This comment's bytes are processed character by character. */
* Asterisk comments are read token by token but quotes are treated like single tokens.;
(However, inside a macro definition, they are gathered as constant text. So the constant text is built with tokenization rules, including string literal tokens.)
%* This macro comment is read token by token until the semicolon.;
To understand the descriptions above, it is important to understand what a token is. A word or token in the SAS programming language is a collection of characters that communicates a meaning to SAS and which cannot be divided into smaller units that can be used independently. A word can contain a maximum of 32,767 characters.
A word or token ends when SAS encounters one of the following:
Each word or token in the SAS language belongs to one of four categories:
Look at a few examples of using these different styles of comments within a macro:
Example 1 (macro style comment):
%macro test(dsin); %* Shouldn't the single quotation mark be ignored since comment?; proc print data=&dsin; run; %mend; data test; i=1; run; %test(test)
The macro comment begins and we start processing tokens after the '%*'. The first token is received as "Shouldn". The word scanner looks for the next token or semicolon to end the comment. The word scanner finds a single quotation mark and begins to gather characters looking for the next single quotation mark in order to make a string literal. Starting with the single quotation mark, the following is read as part of the literal string:
't the single quotation mark be ignored since comment?; proc print data=&dsin; run; %mend; data test; i=1; run; %test(test)
The word scanner is still looking for the closing single quotation mark. As you continue to submit code, the word scanner continues to read characters looking for a closing quotation mark. The maximum length of a character value is 32,767 bytes. However, if you reference a quoted string that is longer than 262 bytes, the following warning message is issued:
WARNING 32-169: The quoted string currently being processed has become more than 262 characters long. You may have unbalanced quotation marks.
To fix this, use the PL/1 style comment instead.
Example 2 (asterisk style comment):
%macro one; * This is a test %let x = this would not work; data new; set one; run; %mend; %one
What happens is:
%ONE is executed:
ERROR 180-322: Statement is not valid or it is used out of proper order.
This error is generated because the semicolon that ended the DATA statement actually ended the asterisk style comment. This means that the DATA statement is now part of the comment leaving the SET statement out in open code.
In a macro definition, everything is compiled from the end of the %MACRO statement to the %MEND:
The important rule to remember here is that asterisk style and macro style comments are read token by token until a semicolon is found. PL/1 style comments are read character by character.
The safest comment to use inside a macro is the PL/1 style comments in the form of /* comment */. Since this style of comment is read character by character, special characters and macro triggers such as % and & do not cause a problem and are truly seen as a comment.
|Product Family||Product||System||SAS Release|
|SAS System||Base SAS||z/OS|
|Microsoft® Windows® for 64-Bit Itanium-based Systems|
|Microsoft Windows Server 2003 Datacenter 64-bit Edition|
|Microsoft Windows Server 2003 Enterprise 64-bit Edition|
|Microsoft Windows XP 64-bit Edition|
|Microsoft® Windows® for x64|
|Microsoft Windows 95/98|
|Microsoft Windows 2000 Advanced Server|
|Microsoft Windows 2000 Datacenter Server|
|Microsoft Windows 2000 Server|
|Microsoft Windows 2000 Professional|
|Microsoft Windows NT Workstation|
|Microsoft Windows Server 2003 Datacenter Edition|
|Microsoft Windows Server 2003 Enterprise Edition|
|Microsoft Windows Server 2003 Standard Edition|
|Microsoft Windows XP Professional|
|Windows Millennium Edition (Me)|
|64-bit Enabled AIX|
|64-bit Enabled HP-UX|
|64-bit Enabled Solaris|
|ABI+ for Intel Architecture|
|Linux for x64|
|Linux on Itanium|
|OpenVMS on HP Integrity|
|Solaris for x64|
|Date Modified:||2016-03-18 11:10:54|
|Date Created:||2008-07-16 11:54:28|