BookmarkSubscribeRSS Feed
SasStatistics
Pyrite | Level 9

I am working in an organization where there are multiple users and multiple people write custom macros that are included in other programs. Programs and macros are saved in servers (not on local computer memory) so it is accessible to multiple people - I give this background information since it could affect the arguments against and for below. 

To make the macros available, we simply use %include statements in the programs where one %include file can contain around 40 macros and then use them. This works fine, but I am curious of if there are any "best practices" or recommendations on how to "professionally" do it. Arguments for and against are appreciated and any best practices aswell. 

Thanks.  

3 REPLIES 3
PaigeMiller
Diamond | Level 26

I recommend using an AUTOCALL macro library, for the same reasons given in this thread. https://communities.sas.com/t5/SAS-Programming/SAS-Macro-Help-Text-Documentation/m-p/753876#M237672

 

I use an AUTOCALL library. I haven't typed %include since the 16th century.

 

The disadvantage of using %include to include a file with about 40 macros is that all these macros have to be compiled at the time the %include command is issued, and this may take a minute or so (I don't know, they're not my macros). Further disadvantage of having 40 macros in one file is that they become difficult to manage and/or modify in one file. First, you have to find the macro you want to modify. Then, don't make a mistake when you modify it! If there is a mistake in one of the macros, it could affect every macro below it, or you could accidentally modify other macros.

 

 

--
Paige Miller
Quentin
Super User

Agree, read up on setting up and using autocall libraries.  They're wonderful.

 

And note your SAS program can determine which autocall libraries it uses, they they will be searched in order.  Every SAS session (by default) already has an autocall library, with macros provided by SAS.  So you can add say a corporate macro library, and even a project-specific macro library.  Then when you call a macro, it will look in project-specific macro library to see if it exists, then look in the corporate library, then look in the SAS default library.  It's great.

 

When I first started writing general purpose macros for my own use, I used the %include method.  I had one  .sas file for each macro.  So I had a folder with say 30 .sas files.  Then I had one .sas file LoadMacros.sas which  was a list of 30 %include statements.   At the start of a program, I would %include LoadMacros.sas, and it would compile all the macros.  But that was basically just a hack that felt useful until I learned about the benefits of using an autocall library.

 

If you go to lexjansen.com, you should find plenty of papers about setting up and managing autocall libraries. They work great, for teams and individuals.  Or buy Art Carpenter's macro programming book.

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
PaigeMiller
Diamond | Level 26

Regarding project specific macros, I have created different AUTOEXEC files for different projects, so it can access the specific AUTOCALL macro I need for a specific project, but perhaps set other options as well (such as output folders, titles or footnotes, etc., access to databases) that would be specific to this project.

--
Paige Miller

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 586 views
  • 4 likes
  • 3 in conversation