BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

This is not exactly a request for solutions, but an invitation for comments.  Maybe someone has brought this to SAS' attention already.

 

The discussion starting out the documentation for %* Macro Comment Macro Statement is not being challenged here.  Instead I am focusing on an example in this section intended to show that an ordinary comment statement (beginning with * or with COMMENT) does NOT mask the comment content from the macro processor (hence the need for /* */ or %*).  It does show that property alright, but a little more pathologically than intended.

 

The example is as follows:

%macro verdata(in, thresh);
    *%let thresh = 5;
    /* The preceding SAS comment does not hide the %let statement
        as does this type of SAS comment.
        %let thresh = 6;
    */
   %if %length(&in) > 0 %then %do;
         %* infile given;
      data check;
           /* Jim's data */
         infile ∈
         input x y z;
            * check data;
         if x<&thresh or y<&thresh or z<&thresh then list;
      run;
   %end;
   %else %put Error: No infile specified;
%mend verdata;
%verdata(ina, 0)

which the documentation asserts will produce this sas program:

DATA CHECK;
   INFILE INA;
   INPUT X Y Z;
      * CHECK DATA;
   IF X<5 OR Y<5 OR Z<5 THEN LIST;
RUN;

Nope.  It actually produces this sas code: 

* data check;
infile ina;
input x y z;
* check data;
if x<5 or y<5 or z<5 then list;
run;

... and a lot of error messages in the sas log.

 

This is ironic, since while successfully showing that the *%let thresh=5; causes macro processor to ignore the asterisk and assign a value of 5 to thresh, it also shows that the resulting %let macro statement absorbs the semicolon, thereby converting the subsequent data statement into a comment (pesky little asterisk left untouched by macro).

 

The latter consequence was overlooked in the documentation.  I don't think the example was actually tested (also revealed by the fact that the purported resulting code is capitalized even though the source code inside the macro wasn't).

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You are right.

Click on the Feedback link on that documentation page and report the issue to the documentation team.  They are very happy to get constructive feedback like this.

 

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

You are right.

Click on the Feedback link on that documentation page and report the issue to the documentation team.  They are very happy to get constructive feedback like this.

 

 

mkeintz
PROC Star

@Tom wrote:

You are right.

Click on the Feedback link on that documentation page and report the issue to the documentation team.  They are very happy to get constructive feedback like this.

 

 


Done.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 335 views
  • 0 likes
  • 2 in conversation