将 mymacro /source 复制到另一个库?

Copy mymacro /source to another library?

假设我按以下方式存储了一个宏:

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

现在我想将这个宏从库 FOO 复制到库 BAR,我想要类似的东西(这显然行不通):

%copy hello_world /source LIB = BAR;

这相当于:

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

目标是方便地将宏从开发库复制到生产库。我该怎么做?

Proc CATALOG用于将条目从一个成员复制到另一个成员

%macro One;
%put ONE;
%mend;

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

复制条目的替代方法是使用 LIBNAME 自动提供的串联功能。

来自 SAS 帮助

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.

如果同名目录包含同名条目,则使用最早的库中的条目。

这在单元测试期间非常方便,因为在更新被证明不会造成破坏之前不必更改原始文件。你有集成单元测试吗? ;-)

如果您只想将宏移至生产环境,PROC CATALOG 是正确的方法。

*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;

现在,我可能不会这样做 - 我会使用 git 来存储和部署源文件 - 但如果您更喜欢存储的编译宏,这是最好的方法。