Search code examples
sassas-macro

How to i use %include to invoke a SAS macro


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?


Solution

  • %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.