BookmarkSubscribeRSS Feed
SasStatistics
Pyrite | Level 9

In my organization we have many macros and we store them by category in scripts. So we have let's say 15 scripts each containing about 15 macros. 

When running other scripts we include the categorys we need by an %include statement. So one script containing an analysis could contain 3 %include statements since we need macros from 3 different categories. 

Now, as far as I have understood this is not the "way to do it" and one should (Best practice?) use Autocall libraries. 

So, I would like to do it and if anyone could give the steps one normally undertakes that would help alot (when reading about it I find it a bit confusing). 


- For instance, the first step I have to do, I believe is to split the scripts containing the macros into seperate files and put the macros for each category in a seperate folder? 

If I for instance would like to include macros from a folder called category 1 in a script, what code should I write at the top of the script to include those macros? 


 

5 REPLIES 5
yabwon
Onyx | Level 15

The simplest would be:

 

options 
MRECALL
MAUTOSOURCE
SASAUTOS = (sasautos '/your/location/of/macro/files');

Links to the doc:

 

Saving Macros in an Autocall Library:

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n1o5fkxq0gqdpcn1xs3ksdks69tf.htm

MAUTOSOURCE Macro System Option:

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n1fbcsjdhakzywn1qg28id3gl0ph.htm

SASAUTOS= Macro System Option:

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p12b2qq72dkxpsn1e19y57emerr6.htm

MRECALL Macro System Option:

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n0cfvf12looza7n10yaa4foizemd.htm

 

I would also checked out the APPEND= system option:

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lesysoptsref/p1q9ay0ai0h2ein1n68qxomnm3q7.htm

 

 

As an alternative approach I would also recommend you to check out the idea of SAS Packages. The details are here:

https://github.com/yabwon/SAS_PACKAGES (links also in my signature's footer)

 

All the best

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



japelin
Rhodochrosite | Level 12

I think you can use SASAUTOS to make automatic calls.

 

One more thing. I would also suggest using stored macros.
You will have to rewrite the macro code a bit, though.

You can consolidate your macros into one catalog for each category, or you can combine all of them into one macro catalog if they don't have the same macro name.

 

 

LIBNAME mylib 'C:\temp';
OPTIONS MSTORED SASMSTORE=mylib; 

%MACRO msample /STORE;/* Macro stored in mylib.SASMACR */
/* Macro code */
%MEND msample;

 

 

when next SAS session.

LIBNAME mylib 'C:\temp';
OPTIONS MSTORED SASMSTORE=mylib; 

%msample;/* not %include need! */

 

 

Quentin
Super User
Curious why you prefer using stored compiled macros? Is it just to avoid the time to compile a macro the first time it is called? I've always thought the risks/hassle of using stored compiled macros outweighed the benefits. I know some folks use them because they want to hide/secure/encrypt their source macro code.
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.
SASKiwi
PROC Star

I would definitely regard using AUTOCALL macros as best practice. One big benefit is sharing their use across all of your SAS users by including the setup in your SAS server AUTOEXEC.SAS program.

 

Just be careful if you use compiled SAS macros though. If you lose the macro source code you can't restore it from the compiled macros. For that reason alone I tend to steer clear of using them.

 

 

 

AllanBowe
Barite | Level 11

In our organisation, we keep all our macro definitions in a GIT repository, and compile them into each Job or Service or Test before deploying to the target SAS server.

 

That way every SAS program is fully self contained, with all dependencies, and there is no need to fetch code from the server filesystem.  The workflow also plays nicely with GIT for operations such as branching and merging, without impacting other developers on the SAS box.

 

The framework is open source (we built it) and there are multiple guides available here:  https://sasjs.io/resources/

 

 

/Allan
SAS Challenges - SASensei
MacroCore library for app developers
SAS networking events (BeLux, Germany, UK&I)

Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs

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
  • 5 replies
  • 1210 views
  • 4 likes
  • 6 in conversation