Reputation: 17107
If I write a test.sas with the contents:
%macro test;
%put test macro;
%mend;
%test;
And then just execute this at a sas session:
%include test.sas
Will it just invoke the macro 'test'? Or will it just include the macro definition but skip the execution?
Upvotes: 0
Views: 1989
Reputation: 63434
Yes, it will work as you suggest initially - it will compile and run the macro.
I would note that good programming style would be to have the macro invocation in your actual program (if that's all you're doing). This is like a C++ header file: the macro contains 'what to do', then you actually invoke it in your live code - not only for nice style, but for the ability to rerun it without recompiling it if you need to (to fix something, say).
Upvotes: 1
Reputation: 12909
%include
is like hitting F3 on an external file. It will try to compile and execute everything in the text file. So, if you turn on mcompilenote=all
and your program is:
%macro test;
%put test macro;
%mend;
%test;
The log will read:
8 %macro test;
9 %put test macro;
10
11 %mend;
NOTE: The macro TEST completed compilation without errors.
6 instructions 80 bytes.
12 %test;
test macro
But, if your program is:
%macro test;
%put test macro;
%mend;
The log will read:
8 %macro test;
9 %put test macro;
10
11 %mend;
NOTE: The macro TEST completed compilation without errors.
6 instructions 80 bytes.
Upvotes: 0
Reputation: 51621
It will execute the statements in the file the same as if they were included as lines in the original program. So it will first define the macro and then when the last line is run it will execute the macro.
Upvotes: 0