09-27-2016 05:38 AM - edited 09-27-2016 05:43 AM
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.
09-27-2016 05:55 AM
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;
- That still only counts as one -
09-27-2016 06:10 AM
It depends on how the macro is included. In your program or setup/autoexec.sas 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?
09-27-2016 06:53 AM
If stored in a catalog try %copy to see code in your log.
Otherwise look at MAUTOLOCDISPLAY and/or SASAUTOS option via getoption() function.
09-27-2016 08:04 AM
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: http://support.sas.com/kb/42/654.html
Hope that helped,