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.

BASUG is hosting free webinars Next up: Don Henderson presenting on using hash functions (not hash tables!) to segment data on June 12. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 379 views
  • 4 likes
  • 3 in conversation