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.
hello,
use macro options - mprint, symbolgen, mlogic to see the code generated by the macro.
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 -
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?
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));
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,
Patrick
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.