BookmarkSubscribeRSS Feed
SAJ251
Calcite | Level 5

How do I dynamically create a list of all macro functions created in a program.  I know how to obtain a list of reference macros, but not macro functions.  How do I do that?  The macro functions are temporary - created everytime the program is run.  I'm trying to create  documentation for code others run since they have don't have any documentation.

6 REPLIES 6
Tom
Super User Tom
Super User

"functions"?

 

If you want to scan code to see if it defines any macros look for the %MACRO statement.

 

If you want to check after running a program what macros are defined you can look at the WORK.SASMACR (or SASMAC1 if using Enterprise Guide or SAS/Studio or other esoteric way to submit SAS code) and see what macro entries are there.  For an example of how to do that look at this macro:  https://github.com/sasutils/macros/blob/master/maclist.sas

 

 

 

Quentin
Super User

I like Tom's idea of checking WORK.SASMACR.  

 

You could write a macro, %ReportMacrosUsed which will look in WORK.SASMACR and get a list of all of the macros there, and write that list and the name of the program somewhere useful (a file, database, email, whatever).  Then tell all of your users to add a call to %ReportMacrosUsed to the end of their programs.

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
Tom
Super User Tom
Super User

You could use the %MACLIST() macro to make a VIEW and then just ask them to print the VIEW at the end of their programs.

 

Make the view into some fixed location.  Say your company has a SYSTEM library where you store common data for them to use then your admins could run this %MACLIST() call to make the view.

%maclist(out=system.maclist/view=system.maclist)

Then the users can add this step to the end of their programs:

proc print data=system.maclist;
  title "Macros used by this run";
run;

 

Quentin
Super User

Do you mean all macro definitions in a program? 

 

What you do you mean by reference macros and macro functions?

 

Since SAS programs are text files, you could use SAS (or something else) to parse a .sas file to look for %macro statements and grab them name of each macro, but it would be a bit of an exercise.

 

Another option might be to turn on logging options like MCOMPILENOTE which will write to the log when a macro is compiled.  Then you could run a program, and save the log,  and then parse the log to see which macros were compiled.

 

But either way seems kind of messy.

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
yabwon
Onyx | Level 15
1    options MCOMPILENOTE=ALL;
2
3    %macro test1234();
4    xxx
5    %mend;
NOTE: The macro TEST1234 completed compilation without errors.
      5 instructions 52 bytes.
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



yabwon
Onyx | Level 15

you could try like this:

proc sql;
  create table Before_processing as
  select memname, objname, objtype
  from dictionary.catalogs
  where 
  objtype = "MACRO"
  and libname  = "WORK"
  ;
quit;


/*
your code goes here
*/
/*For example:*/
/* packages to be loaded at the system start */
filename packages "C:\SAS_WORK\SAS_PACKAGES";
%include packages(SPFinit.sas);
%loadPackage(BasePlus)





Title "Newly created macros";
proc sql;
  create table After_processing as
  select memname, objname, objtype
  from dictionary.catalogs
  where 
  objtype = "MACRO"
  and libname  = "WORK"
  ;
  select * from After_processing
    except
  select * from Before_processing
  ;
quit;
Title;

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



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 25. 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
  • 6 replies
  • 858 views
  • 1 like
  • 4 in conversation