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

I am trying to figure the way to properly put comments within macros. But I am trying to do it as a trick while working my way through Cody's Collection of Popular SAS Programming Tasks. I am basically going through the book, example by example, and learning a lot as I go along. As part of this I have a set of syntax saved in my Enterprise Guide. I do not delete the previous code, but I use a "trick" that Marty Hultgren showed to me a few weeks ago. Specifically by putting %macro SKIP; at the beginning of the code then a %mend; at the end it skips over all of the previous code I had written in SAS and starts fresh with the new code at the bottom. It is sort of like a grand way of commenting out large blocks of code.

Some of the newer examples in the Cody book have the reader try a few different ways of accomplishing simple tasks. Specifically I am looking at ways of combining summary information with detail data - sort of appending a grand mean to each individual record. I can do it via PROC MEANS or with PROC SQL. I commented out the previous way that I did it while working through the code. I am including a picture of what I did and the associated warning. Overall it gives a message about the quoted string being more than 262 characters. I did some investigating and there are varying rules for including comments within a macro. Below is a link to the technical support with SAS:

32684 - Using comments within a macro

But overall I cannot figure what I am doing wrong. This warning has come about previously for me - the solution I have always used in the past is to shut SAS down and get into it again, but it is not working this time. Thank you very much in advance.

Capture.JPG

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

My rule is no apostrophes in comments, just for this reason.  You never know when a * comment in open code might later end up as a comment inside a macro.

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

View solution in original post

8 REPLIES 8
Tom
Super User Tom
Super User

1) Your problem is unbalanced quotes.  DO NOT use unbalanced quotes. That means don't use don't (unless you use it in pairs).  You can get away with them in a statement style comment in open code, but inside of a macro they cause trouble.

2) If you are using EG then the equivalent of re-starting SAS is to disconnect and re-connect your Server Session. Someone more familiar with EG can explain.

As to the general question of comments in macros. Personally I use statement style comments for comments that I want to appear in the LOG when MPRINT is turned on.  I make each such comment its own line starting * and ending with ; so that when generated by MPRINT it is still readable.   The comments are BEFORE the code that they are referencing.  Putting them at the end of the line of code makes the MPRINT lines look backwards.

For comments that are really for the person editing the program (not running the program and reading the log) I use MACRO comments.  Start the comment with %* and end it with ; . You can make these longer than a line since they will not be emitted by MPRINT.

Rarely I will use PL/1 style comments (/* ... */).   There are two situations where they are needed.

1) when the comment needs to be in the middle of a statement, especially a macro statement.

2) when the comment needs to include example lines of code with semi-colons and other macro triggers.

Zachary
Obsidian | Level 7

It turns out that a few parts were messing me up. First, I had an apostrophe within my macro for a comment within there. That sort of threw things off. No issues of unbalanced quotes.

I actually thought for a while that because I had such a large macro it was interpreting this as a very long text string of sort. That was also not true.

I also was using statement-style comments within the macro - but these do not work, at least under tricky conditions. Only %* as well as /* ... */ work within macros.

Lastly, the good SAS rep recommended %mend; being done repeatedly rather than re-booting SAS if it gets hung up.

Thank you.

Quentin
Super User

My rule is no apostrophes in comments, just for this reason.  You never know when a * comment in open code might later end up as a comment inside a macro.

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
Tom
Super User Tom
Super User

Statement style comments are actually more useful in macros than in open code. In open code all comments will appear in the log,  But in a macro only the statement style comments will appear in the log with the statements when MPRINT is turned on.  Just don't use unbalanced quotes in the comments.

The only time I have seen statement style comments cause trouble in macros is when attempting to use RSUBMIT blocks to submit macro definitions.

jakarman
Barite | Level 11

Tom, remember the scope of a macro. When using rsubmit blocks those are operating in a different machine having a different scope. During macro compilation its hardly noticed but during macro execution it makes a big difference as you are back at global level and the first macro definition in a macro for that part is starting at level 1 again. Not being nested as you could think of seeing some coding.

---->-- ja karman --<-----
Tom
Super User Tom
Super User

That can get complicated, but the problem I have seen is internal to SAS.  It just does the wrong thing.  It always looked to me like the process of moving the code from the one session to the remote session was causing tokens to get broken in the middle.

jakarman
Barite | Level 11

It did not get too complicated when following that scope logic. It was not well documented in the old versions, recently seen this.

SAS(R) 9.4 Macro Language: Reference, Third Edition  %SYSRPUT Statement -   Example: Checking the Value of a Return Code on a Remote Host 
That rsubmit/endrsubmit is now easilty to see as part of a grand macro process. Those rsubmit / endrsubmit can be made conditional so the code can run balanced remote or as whole local. Using the %syslput %sysrput for synching macrovars and not the %let or %put (global ones) as those are timed wrong. Getting compiled local where the intention was being run remote. When embedded in that remote macro there is no scope issue anymore. Also you cannot get hurt what you would see as broken tokens.
some things with quoting cahllenges still remains.

---->-- ja karman --<-----
jakarman
Barite | Level 11

It is about tokens: SAS(R) 9.4 Macro Language: Reference, Third Edition. And that token processing as given is not always the same as the color highlighting.

---->-- ja karman --<-----

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 8 replies
  • 1311 views
  • 7 likes
  • 4 in conversation