There are three kinds of comments: PL/1 style, asterisk style, and macro style.
1.) PL/1 style comments are processed in the SAS wordscanner, character by character.
/* This comment's bytes are processed character by character. */2.) Asterisk style comments are processed in the tokenizer, token by token, until a semicolon is reached. However, single and double quotation marks are treated as special tokens, so that string literal tokens are NOT built in this case.
* Asterisk comment's are read token by token but quotes are treated(However, inside a macro definition, they are gathered as constant text. So the constant text is built with tokenization rules, including string literal tokens.)
like single tokens.;
3.) Macro style comments are processed by the macro facility, token by token, until a semicolon is reached. Single and double quotation marks build string literals, so every open quote must have a closing quotation mark.
%* This macro comment is read token by token until the semicolon.;
To understand the above descriptions, 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: • the beginning of a new token • a blank after a name or a number token • the ending quotation mark of a literal token. Each word or token in the SAS language belongs to one of four categories: • names • literals • numbers • special characters.
Take a look at a few examples 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 starts processing tokens after the '%*'. The first token is received as "Shouldn". It looks for the next token or semicolon to end the comment. The wordscanner finds a single quote 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 wordscanner is still looking for the closing single quotsyion mark. As you continue to submit code, the wordscanner will continue reading 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: 1. The string "* This is a test " is stored as TEXT. 2. %LET is stored as interpreted code until the semicolon. 3. The remaining code is pushed as text. %ONE is executed: 1. The string "* This is a test " is pushed on as source. It will wait for a semicolon to end the comment. 2. The %LET executes creating a macro variable. 3. ‘data new;’ is seen next and since the comment is still waiting for a semicolon, this semicolon stops the asterisk style comment from eating tokens. 4. ‘set one;’ is seen next; but since the DATA statement is now part of the comment, you get the following error: ERROR 180-322: Statement is not valid or it is used out of proper order.
The reason for this error is because the semicolon that ended the DATA statement actually ended the asterisk style comment which 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
-non-macro code becomes text that will be pushed out during execution -macro statements become interpreted code (%DO, %LET)
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 are the PL/1 style comments in the form of /* comment */. Since this style 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:||2013-05-21 10:25:10|
|Date Created:||2008-07-16 11:54:28|