Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_include.sas File Reference

Performs a wrapped %include. More...

Go to the source code of this file.

Detailed Description

This macro wrapper is necessary if you need your included code to know that it is being %included.

If you are using include in a regular program, you could make use of the following macro variables:

  • SYSINCLUDEFILEDEVICE
  • SYSINCLUDEFILEDIR
  • SYSINCLUDEFILEFILEREF
  • SYSINCLUDEFILENAME

However these variables are NOT available inside a macro, as documented here: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n1j5tcc0n2xczyn1kg1o0606gsv9.htm

This macro can be used in place of the include statement, and will insert the following (equivalent) global variables:

  • _SYSINCLUDEFILEDEVICE
  • _SYSINCLUDEFILEDIR
  • _SYSINCLUDEFILEFILEREF
  • _SYSINCLUDEFILENAME

These can be used whenever testing within a macro. Outside of the macro, the regular automatic variables will still be available (thanks to a concatenated file list in the include statement).

Example usage:

filename example temp;
data _null_;
  file example;
  put '%macro test();';
  put '%put &=_SYSINCLUDEFILEFILEREF;';
  put '%put &=SYSINCLUDEFILEFILEREF;';
  put '%mend; %test()';
  put '%put &=SYSINCLUDEFILEFILEREF;';
run;
%mp_include(example)
Parameters
[in]filerefThe fileref of the file to be included. Must be provided.
[in]prefix=(_) The prefix to apply to the global variables.
[in]opts=(SOURCE2) The options to apply to the inc statement
[in]errds=(work.mp_abort_errds) There is no clean way to end a process within a include called within a macro. Furthermore, there is no way to test if a macro is called within a include. To handle this particular scenario, the mp_abort() macro will test for the existence of the _SYSINCLUDEFILEDEVICE variable and return the outputs (msg,mac) inside this dataset. It will then run an abort cancel FILE to stop the include running, and pass the dataset back.

IMPORTANT NOTE - it is NOT possible to read this dataset as part of this macro! When running abort cancel FILE, ALL macros are closed, so instead it is necessary to invoke "%mp_abort(mode=INCLUDE)" OUTSIDE of macro wrappers.

Version
9.4
Author
Allan Bowe

SAS Macros

Definition in file mp_include.sas.