BookmarkSubscribeRSS Feed
RahulG
Barite | Level 11

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. 

5 REPLIES 5
Loko
Barite | Level 11

hello,

 

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

Oligolas
Barite | Level 11

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 -

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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?

Reeza
Super User

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));

 

 

 

 

Patrick
Opal | Level 21

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

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1943 views
  • 0 likes
  • 6 in conversation