I want to store macros in a catalog. Doing so allows many macros to be shared with just a single file, as well as introduces a degree of separation from the user.
To store my macro, I run a program such as
/* HelloWorld.sas */
libname pwd "."; /* assign current directory */
option mstored sasmstore=pwd; /* set pwd as storage directory */
%macro HelloWorld()
/ store source; /* store compiled macro along with its source */
data _null_;
put "Hello, World!";
run;
%mend;
This creates a sasmacr.sas7bcat
file in the directory in which HelloWorld.sas
lives. I can then move that file to another directory, such as C:\myMacros
and run the following program:
/* CallHelloWorld.sas */
libname myMacros 'C:\myMacros';
option mstored sasmstore=myMacros;
%HelloWorld();
The macro HelloWorld()
is called without error.
However, if I want to consider the HelloWorld()
macro as part of a "HelloWorld" macro suite, I cannot simply change the catalog name in Windows Explorer from sasmacr.sas7bcat
to HelloWorld.sas7bcat
. When I do this and try running CallHelloWorld.sas
again (after closing and reopening SAS), the macro is not resolved.
1 /* CallHelloWorld.sas */
2 libname myMacros 'C:\myMacros';
NOTE: Libref MYMACROS was successfully assigned as follows:
Engine: V9
Physical Name: C:\myMacros
3 option mstored sasmstore=myMacros;
4
5 %HelloWorld();
-
180
NOTE: The SAS System was unable to open the macro library referenced by the SASMSTORE = libref
MYMACROS.
WARNING: Apparent invocation of macro HELLOWORLD not resolved.
ERROR 180-322: Statement is not valid or it is used out of proper order.
ERROR: Catalog MYMACROS.SASMACR does not exist.
NOTE: The SAS System was unable to open the macro library referenced by the SASMSTORE = libref
MYMACROS.
ERROR: An error occurred during the execution of the %COPY statement.
How do I change the name of a catalog which contains macros so that those macros may be called in various programs? Is it possible to name the catalog something different than sasmacr
up front?