DATA Step, Macro, Functions and more

save macro in library?

Not applicable
Posts: 0

save macro in library?

Can you save a group of macros in a library type folder? I want to be able to have access to all of my macros without having to open and rerun each macro file.

Can you do something like

libname library 'C:\macros';

%macro library.sortby(filename, var);
proc sort data=&filename;
by &var;
%mend library.sortby;

Then next time I open sas I can just run

libname library 'C:\macros';

and have access to these macros?
Posts: 9,368

Re: save macro in library?

Posted in reply to deleted_user
The Macro facility has several ways for you to streamline and call already defined and debugged macro programs. For more information, reference the macro documentation topic, entitled Storing and Reusing Macros:

which is composed of these 3 sub-topics:
Introduction to Storing and Reusing Macros
Saving Macros in an Autocall Library
Saving Macros Using the Stored Compiled Macro Facility

Respected Advisor
Posts: 4,736

Re: save macro in library?

Posted in reply to Cynthia_sas
The most convenient way for what you want to achieve (avoid re-running) would be an Autocall Library (SASAUTOS).
Posts: 48

Re: save macro in library?

Posted in reply to deleted_user
Yes you can.

Storing a macro:
libname AAA "C:/macros";
options mstored sasMSTORE=AAA;
%macro TestStore/store;
%put stored macro;
%mend testStore;

The macro will be stored in library AAA.

If you want to use it, you have to use the same option, and assigned library AAA.

libname AAA "C:/macros";
Valued Guide
Posts: 2,191

Re: save macro in library?

Posted in reply to deleted_user
others have provided guidance to a proper solution, so there is little left for me to add,
except to show how you can save macros in a library.
I'm referring to macro code. Not the compiled macros (which when compiled can be stored and retrieved through the mstored and sasmstore options)..[pre]filename macros catalog team.macros ;[/pre]where TEAM would be a libref (perhaps) pointing at a shared area.
The filename engine CATALOG, allows us to store source like macro code progrms, in catalog entries.. The catalog can be addressed usin the fileref as "an aggregate storage location", just like a folder in hierarchical storage or a pds in zOS.

you still need to refer to the macros catalog fileref in the sasautos option value, but you have your
"macros saved in a library"

Ask a Question
Discussion stats
  • 4 replies
  • 5 in conversation