0

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?

Victor
  • 16,609
  • 71
  • 229
  • 409

3 Answers3

1

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).

Joe
  • 62,789
  • 6
  • 49
  • 67
0

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.

Tom
  • 47,574
  • 2
  • 16
  • 29
0

%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.
Stu Sztukowski
  • 10,597
  • 1
  • 12
  • 21