BookmarkSubscribeRSS Feed
DJWanna
Obsidian | Level 7
We are having a bit of a debate here ... I am an old time SAS programmer who was told that it is better to semicolon after a macro call ... %macroname; There is another thought that one must never semicolon ... %macroname.

My thinking is that if there were unbalanced semicolons at least this one would make sure that the macro would run. However, there is a note in a course note publication that states the opposite. I know there are times when if a macro call was in the middle of other code it may not be appropriate. I am just wondering about the call itself as stand alone code.

Your thoughts?
Thanks!
5 REPLIES 5
Flip
Fluorite | Level 6
After 25 years, I almost always put in the semicolon. I have known programmers who put a semicolon in empty lines as spacers. In most cases it will not hurt, and helps locate things in debugging.

I also insist on hard returns and RUN; statements which I often see left out of code.
Peter_C
Rhodochrosite | Level 12
another old $0.02
sometimes the statement needs to be completed with a semicolon after the macro is called.
The macros which generate steps, usually, finish by generating a semicolon on a "run;" Those which generate only statements usually deliver statements completed by a semicolon. These macro invocations should not need a trailing semicolon.
I use a lot of "sub-statement" macros. They are really useful when a string or value needs to be retrieved. These "sub-statement macros" generate no semicolon so that they can be used, for example, in a calculation. It is normally important that these sub-statement macros are not immediately followed by a semicolon.
For example:
%put the message at %now() needs action ;

The semicolon ends the statement, not the macro invocation.

PeterC
Flip
Fluorite | Level 6
Agreed. One really needs to know the context in which a macro is to be used. In the case of a sub-statement type of macr. I make it clear in the documentation if no semi-colon is to be used.
ChrisNZ
Tourmaline | Level 20

The semicolon after the macro call will never be used, will it? (actually if it is part of the logic of the macro-generated code, it should be inside the macro itself).

The only reasonable case when a semicolon will be used after the macro call is when it closes a non-macro statement, as in
title %write_title(big, red, bold);
but then the semicolon is there to close the title statement, not as part of the macro call.

>I have known programmers who put a semicolon in empty lines as spacers.

Unless you are one of these and like extra and unused semicolons, a semicolon after a macro call makes no sense.

My 2 cents, to each their own and all that. Having an extra ; is not a big sin (though it sometimes hides bad understanding of how macros work).

 

Edited. The deficient  color parser is sadly a reason to use an ending semicolon, as it gets confused without this explicit statement delimiter.

DanielSantos
Barite | Level 11
Yep, agree with Chris. No need for any semicolon after the macro call.

But in my case, sometimes the habit of terminating any line of code with a semicolon takes over this understanding. Indeed, not a big sin.

Now, a situation that I found to be particularly confusing to understand for some sas coders is the need of a semicolon after the %if %then macro statement, say something like this:

%macro x(TAB,KEEP,VARS);

data _null_;
set &TAB %if &KEEP %then (keep = &VARS);;
run;

/* OR */

data _null_;
set &TAB %if &KEEP %then (keep = &VARS); end = _EOF;
run;

%mend x;

Cheers from Portugal.

Daniel Santos at www.cgd.pt.

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
  • 5 replies
  • 4929 views
  • 2 likes
  • 5 in conversation