Hello Team,
How i can get list macros which are used in a single program.
In one program used 5 macros and 3 of macros have 10 nested macros.
So i need to get list of all macros names with nested macros names in a program.
Thank you,
Rajasekhar.
Not an easy way. Especially when macros can be nested three or four deep.
Best would probably be to take a log of the program (run with MPRINT turned out) and parse it to locate the macro names from the log. Then sort and remove duplicate names.
Even so, that doesn't tell you the library that holds the macro. There could be more than one macro library.
Try PROC SCAPROC but I don't think anything will get it for you. Also, do you need to separate user defined macros from automatic macros?
If you're only compiling the macros in the process of this program you could look at which macros are available before and after running the code, I think it's stored in a catalogue but cannot remember the specifics so hopefully someone else can :).
Parsing SAS code is hard, so trying to predict in advance of running would be difficult. You could try scanning for text that looks %xxxx and eliminate the known macro keywords and functions from the list.
If you are using AUTOCALL to locate and compile the macros you could run the program and then examine the contents of the catalog where SAS stored the macros it compiles. There are also some new options in SAS that enable writing notes to the SAS log when it compiles a macro.
MAUTOCOMPLOC | Displays in the SAS log the source location of the autocall macros when the autocall macro is compiled. |
---|---|
MAUTOLOCDISPLAY | Displays the source location of the autocall macros in the SAS log when the autocall macro is invoked. |
MAUTOLOCINDES | Specifies whether the macro processor prepends the full pathname of the autocall source file to the description field of the catalog entry of compiled auto call macro definition in the Work.SASMacr catalog. |
Also note that trying to rely on MPRINT option will only find the macros that generate SAS code. Any macro that only generates macro code will not produce any MPRINT lines.
Note detecting the macros used during a run will only find the ones actually called during this run of the program, not any other macros that it might have called if the input data had been different.
hi Tom,
Thank you for suggestion.
I will try to use those options will try to get list from sas log.
Thank you,
Rajasekhar
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.