BookmarkSubscribeRSS Feed
raja777pharma
Fluorite | Level 6

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.

 

 

4 REPLIES 4
Astounding
PROC Star

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.

Reeza
Super User

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 :).

 

 

Tom
Super User Tom
Super User

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.

 

 

raja777pharma
Fluorite | Level 6

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: Call for Content

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4 replies
  • 516 views
  • 2 likes
  • 4 in conversation