- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
The book SAS Certified Professional Guide has this caution:
A semicolon after a macro call might insert an inappropriate semicolon into the resulting program, leading to errors during compilation or execution.
After searching the internet, it seems a lot SAS users think the extra semicolon will not be an issue. Anyone has an example of when the semicolon after a macro call will be an issue?
Thanks
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@cosmid wrote:
The book SAS Certified Professional Guide has this caution:
A semicolon after a macro call might insert an inappropriate semicolon into the resulting program, leading to errors during compilation or execution.
Agree completely, there are situations where a semi-colon after calling a macro is not a problem, and situations where it is a problem. Best to leave it off, and then you never run into a problem with an extra semi-colon in your code.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@cosmid wrote:
The book SAS Certified Professional Guide has this caution:
A semicolon after a macro call might insert an inappropriate semicolon into the resulting program, leading to errors during compilation or execution.
Agree completely, there are situations where a semi-colon after calling a macro is not a problem, and situations where it is a problem. Best to leave it off, and then you never run into a problem with an extra semi-colon in your code.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I've got into error conditions when calling a macro without parameters not using a semicolon.
%macro test;
<some code>
%mend;
%test
This is why I always define and call macros like below even if they don't have a parameter.
%macro test();
<some code>
%mend;
%test()
I personally prefer to end macros with a semicolon even though it's not necessary - except if it's a function style macro used in the middle of some expression where a semicolon of course would terminate the SAS expression in the wrong place. ...but then I avoid such function style macros as far as I can.
Can't think of any other case where this unnecessary semicolon would create issues.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
It is more likely an issue in the reverse situation. You are calling a macro that has defined parameters, but you don't need to pass any parameter values in the call. In that case SAS will wait until it sees the semi-colon to know that the macro call is done.
7 %macro noparms; 8 * This macro does not use parameters; 9 %mend noparms; 10 11 options mprint; 12 %noparms MPRINT(NOPARMS): * This macro does not use parameters; 13 %macro parms(x=1); 14 * This macro does use parameters; 15 %mend parms; 16 17 options mprint; 18 %parms
If you know the macro you are calling is going to generate one or more complete statements then adding a semi-colon does no harm and could fix the problem above when running interactively.