As the first step in the decommissioning of the site has been converted to read-only mode.

Here are some tips for How to share your SAS knowledge with your professional network.

Compiled Stored Macros - Updating

From sasCommunity
Jump to: navigation, search

Problem: When a compiled stored macro is updated, the catalog becomes locked until the session closes and cannot be read. Likewise, when a compiled stored macro catalog is read, it cannot be updated until the session closes.

Solution: copy the macro catalogs from/to a work space prior to reading or updating.

For example, to write the macro "test" to a macro catalog, use the following code:

 * Set up the temporary catalog for writing;
 %macro setMacroLib;
    * Only define the library once, so that this code can be executed several times per session;
    %if %bquote(%sysfunc(pathname(MACTMP))) = %str() %then 
        libname MACTMP "%sysfunc(pathname(WORK))";;
    options mstored sasmstore=MACTMP;
 %mend setMacroLib;
 * Write the macro to the temporary catalog;
 %macro test /store;
    %put This is a test of the emergency broadcast system;
 %mend test;
 * Copy the temporary catalog to a permanent location;
 libname MACLIB '/catalogPath';
 proc catalog catalog = MACTMP.SASMACR;
    copy out = MACLIB.SASMACR;

To read the macro catalog that contains "test," use the following code:

%macro loadMacroLib;
    libname MACLIB '/catalogPath';
    * The temporary catalog can only be defined once per session;
    %if %bquote(%sysfunc(pathname(MACTMP))) = %str() %then %do;
        * Initialize temporary location of catalog;
        libname MACTMP "%sysfunc(pathname(WORK))";
        * Copy permanent catalog;
        proc copy in=MACLIB out=MACS memtype=catalog;
            select sasmacr;
        * Load catalog in temporary location;
        options mstored sasmstore=MACTMP;
%mend loadMacroLib;

One caveat to the above is that any time a macro catalog is updated, the session that uses the macro needs to be restarted. --Sterling Paramore 21:40, 12 May 2010 (UTC)