06-08-2017 07:29 PM
In your example, it wouldn't make much of a difference .. other than you are typing a character (the semi-colon) that isn't needed. You can find a nice explanation, including cases where it would make a BIG difference, at: https://communities.sas.com/t5/Base-SAS-Programming/To-semicolon-or-not-to-semicolon/td-p/60777
Art, CEO, AnalystFinder.com
06-08-2017 07:32 PM - edited 06-08-2017 07:33 PM
you don't need a semicolon at the end of the above macro because the very last statement (%put a; ) has a semicolon in it, so adding a semicolon to %test; would essentially be the same as typing a;;
06-08-2017 09:09 PM
The semicolon is not needed. If you add it, it's like adding a semicolon in the middle of your program. For example, consider:
The top macro call generates:
The second generates:
The extra semicolon is the one that was added when calling the macro. Most of the time, an extra semicolon won't hurt anything. But here are some cases when it will:
In short, adding the semicolon when you call a macro adds the semicolon to the resulting program. Most of the time an extra semicolon is just a null statement and gets ignored. But there are cases when an extra semicolon causes problems.
06-08-2017 09:38 PM - edited 06-08-2017 09:39 PM
Adding a semicolon means you add a semicolon in your code.
Even if unneeded (which is common), it generally won't do any damage [but it could be a problem in the wrong place, for example in something like: where VAR1 = %get_value(param) group by VAR2 ], but often makes no difference.
The colour parser in SAS EG and SAS Desktop editors can get confused if the semicolon is missing, and that's reason I usually add it when I can, even if unneeded.
I'd rather not, but the benefit of better colour parsing outweighs the cost of an extraneous semicolon imho.
06-09-2017 04:43 AM
Personally I find this comes under the same heading as the dot at the end of macro varaibles, and the run; at the end of procedures. Are they needed, not all the time, does it make code more readable yes. Therefore I would always finish a macro variable with a dot:
And I would always put the semi-colon in, and always put run; after each procedure. I don't see any beenfit to not doing this, however there are various downsides, such as coloring in the editor not working, code being less readable, and such like. It also brings up question with people learning when they have seen:
And then think they can get away with it anywhere (this is a question we see here fairly often):
Doesn't do what you thing as there is no dot in the resolved text.
There are instances where not using the semicolo is valid, for instance if I have a macro that resolves to a result then:
Is fine as the macro resolves say to 100 in this case then 100-20; is fine, but 100;-20; is not.
06-09-2017 09:47 AM
@RW9: you said: And I would always put the semi-colon in
Didn't you really mean to say: And I would always NOT put the semi-colon in
Art, CEO, AnalystFinder.com
06-09-2017 10:05 AM
Sorry, I don't follow. I meant that I would always have the code as:
With the semicolon after the macro invocation, except such times as when the macro is used to resolve to a value, in the case of:
This is the only even where I wouldn't have a semicolon as it results in invalid SAS code.