moodymudskipper
moodymudskipper

Reputation: 47320

Copy mymacro /source to another library?

Let's say I stored a macro the following way :

options mstored sasmstore=FOO;
%macro hello_world() / STORE SOURCE DES='hello world';
  %put hello world;
%mend;

Now I want to copy this macro from library FOO to library BAR, I would like something like (this obviously doesn't work):

%copy hello_world /source LIB = BAR;

This would be the equivalent of doing :

options mstored sasmstore=BAR;
%macro hello_world() / STORE SOURCE DES='hello world';
  %put hello world;
%mend;

The goal is to conveniently copy macros from a development library to a production library. How can I do this ?

Upvotes: 0

Views: 488

Answers (2)

Richard
Richard

Reputation: 27508

Proc CATALOG is used to copy entries from one member to another

%macro One;
%put ONE;
%mend;

proc catalog catalog=work.sasmacr;
  copy out=work.holdmacr;
  select one / et=macro;
run;

An alternative to copying entries is to use the concatenation feature that is provided automatically with LIBNAME.

From SAS Help

Example 3: Concatenating SAS Catalogs

This example concatenates three SAS libraries by specifying the physical filename of each and assigns the libref ALLMINE to the concatenated libraries:

libname allmine ('file-1' 'file-2' 'file-3');

If each library contains a SAS catalog named MYCAT, then using ALLMINE.MYCAT as a libref.catref provides access to the catalog entries that are stored in all three catalogs named MYCAT. To logically concatenate SAS catalogs with different names, see the CATNAME Statement.

If the same name catalogs contain same named entries, the entry in the earliest library is used.

This is really handy during unit tests as the original does not have to be altered until updates are proven to be non-damaging. You have integration unit tests right ? ;-)

Upvotes: 2

Joe
Joe

Reputation: 63424

If you just want to move the macro to production, PROC CATALOG is the correct way to do it.

*define foo;
libname foo "c:\temp";

*create the stored macro;
options mstored sasmstore=FOO;
%macro hello_world() / STORE SOURCE DES='hello world';
  %put hello world;
%mend;

*define bar;
libname bar "c:\otherdir";

*proc catalog to copy it over;
PROC Catalog catalog = foo.sasmacr;
             copy out=bar.sasmacr;
run;

***reset SAS session before continuing to clear libname foo***;


*now redirect SAS to BAR;
libname bar "c:\otherdir";
options mstored sasmstore=bar;

*and run hello_World- see it works!;
%hello_world;

Now, I probably wouldn't do it this way - I'd use git to store and deploy the source files - but if you prefer stored compiled macros, this is the best way.

Upvotes: 1

Related Questions