DATA Step, Macro, Functions and more

Macro source code

Super Contributor
Posts: 271

Macro source code

[ Edited ]

I have a macro called "mymacro". When I am calling it, it works well, but I want to find where this macro code is actually saved?


Is there any way to find it out. 

Super Contributor
Posts: 319

Re: Macro source code



use macro options - mprint, symbolgen, mlogic to see the code generated by the macro.

Regular Contributor
Posts: 164

Re: Macro source code

The macro code is not 'saved' it is only compiled in your work directory.

You can store text that is generated by the macro facility during macro execution in an external file. (useful for debugging macros) with ​options mfile mprint;


- Cheers -

Super User
Super User
Posts: 9,599

Re: Macro source code

It depends on how the macro is included.  In your program or setup/ there will be a call to sasautos.  This gives paths or libnames to where macros are stored.  You can also include other files using %include "...\<file>.sas"; So there are a few places where the code can be included.  Also note that if the macros are compiled, i.e. to catalogs, then you may not be able to see the code at all - this is called a black box where you can't see the workings.


I suppose the question here is why do you have a macro and not know where it is?

Super User
Posts: 23,754

Re: Macro source code

If stored in a catalog try %copy to see code in your log. 


%copy macro_name; 


Otherwise look at MAUTOLOCDISPLAY and/or SASAUTOS option via getoption() function. 


%put %sysfunc(getoption(Option_Name));





Respected Advisor
Posts: 4,736

Re: Macro source code

It's unfortunately not a "one stop shop" if you really want to figure out where your SAS code picks up a macro.


If you call a macro in your SAS program, SAS follows a search path to find the macro. The first location a macro with the name you've been calling is found, is the code which gets used.


Macros used in SAS code are compiled; but there is a SAS Autocall facility which allows you to call a macro which hasn't been previously compiled. Such a macro then gets compiled into a catalog in WORK. Any subsequent call of this macro then sources it directly from the catalog in WORK (=compile once, use multiple times).


If you set option "MAUTOLOCDISPLAY" in your SAS session then SAS will write to the log for such cases where it picked up the macro code for compilation into WORK.


It's documented somewhere in the SAS Macro documentation (or SAS Concepts?) but off the top of my head the search path is:

1. macro catalog in WORK

2. macro catalog defined in SOURCE

3. search path as defined in option SASAUTOS

    you can list the full path using the code as available here:


Hope that helped,



Ask a Question
Discussion stats
  • 5 replies
  • 6 in conversation