SAS:如何在目录中存储宏

时间:2016-09-15 14:24:53

标签: sas sas-macro

这是previous post的后续问题。我正试图在这些文章中概述的目录中存储宏,以及我原始帖子中引用的资源:

这是我到目前为止所做的事情:

我创建了一个目录" C:\ myMacros。"首先,我创建了一个名为" HelloWorld.sas"其中包含以下代码:

/* HelloWorld.sas */
option mstored sasmstore=mymacros;
libname myMacros 'C:\myMacros';

%macro HelloWorld() / store source;
    data _null_;
        put "Hello, World!";
    run;
%mend;

代码使用以下日志条目执行:

1    option mstored sasmstore=mymacros;
2    libname myMacros 'C:\myMacros';
NOTE: Libref MYMACROS was successfully assigned as follows:
      Engine:        V9
      Physical Name: C:\myMacros
3
4    %macro HelloWorld() / store source;
5        data _null_;
6            put "Hello, World!";
7        run;
8    %mend;

在SAS文件资源管理器中,活动库" Mymacros"已经创建了名为" Sasmacr"的目录。在Windows资源管理器中检查,我看到" C:\ myMacros \ sasmacr.sas7bcat"已经被创造了。在SAS文件资源管理器中,我点击" Sasmacr"目录并找到" Helloworld"内。当我双击它时,我收到消息框说,

  

宏数据类型没有默认操作。

因此,我得出结论,宏已被编译并存储在" Sasmacr"目录。我关闭了SAS以清除所有内存。

现在,我尝试调用宏。我打开一个新的SAS会话并创建一个名为" CallHelloWorld1.sas"其中包含以下代码:

/* CallHelloWorld1.sas */
libname myMacros 'C:\myMacros';
filename myCat catalog 'mymacros.sasmacr.helloworld.source';
%include myCat;

%HelloWorld();

这会在%include语句中生成错误。

1    /* CallHelloWorld1.sas */
2    libname myMacros 'C:\myMacros';
NOTE: Libref MYMACROS was successfully assigned as follows:
      Engine:        V9
      Physical Name: C:\myMacros
3    filename myCat catalog 'mymacros.sasmacr.helloworld.source';
4    %include myCat;
ERROR: Physical file does not exist, SOURCE  .
ERROR: Cannot open %INCLUDE file MYCAT.
5
6    %HelloWorld();
     -
     180
WARNING: Apparent invocation of macro HELLOWORLD not resolved.

ERROR 180-322: Statement is not valid or it is used out of proper order.

该错误声称物理文件不存在,这与我上面的观察结果相矛盾。所以,我的结论是我错误地称它为正确。根据{{​​3}},SAS四部分名称由 library.catalog.entry.entrytype 组成。我的陈述包括

  1. myMacros
  2. 定义的图书馆:libname myMacros 'C:\myMacros';
  3. 目录:sasmacr
  4. 条目:helloworld
  5. 类型:source
  6. mymacros.sasmacr.helloworld.source。这里肯定有错误,但我无法理解它是什么。

    要尝试其他方法,我再次关闭SAS以清除内存。我创建了#34; CallHelloWorld2.sas"其中包含以下代码:

    /* CallHelloWorld2.sas */
    libname myMacros 'C:\myMacros';
    filename myCat catalog 'mymacros.sasmacr';
    %include myCat(HelloWorld);
    
    %HelloWorld();
    

    这也会在%include行产生错误:

    1    /* CallHelloWorld2.sas */
    2    libname myMacros 'C:\myMacros';
    NOTE: Libref MYMACROS was successfully assigned as follows:
          Engine:        V9
          Physical Name: C:\myMacros
    3    filename myCat catalog 'mymacros.sasmacr';
    4    %include myCat(HelloWorld);
    ERROR: Entry HELLOWORLD.SOURCE not found in catalog MYMACROS.SASMACR.
    ERROR: Cannot %INCLUDE member HelloWorld in the aggregate MYCAT.
    ERROR: Entry HELLOWORLD.SOURCE not found in catalog MYMACROS.SASMACR.
    ERROR: Cannot %INCLUDE member HelloWorld in the aggregate MYCAT.
    5
    6    %HelloWorld();
         -
         180
    WARNING: Apparent invocation of macro HELLOWORLD not resolved.
    
    ERROR 180-322: Statement is not valid or it is used out of proper order.
    

    看来我的宏没有正确存储或者我的调用不正确。但是,资源严重不足。请帮忙!

1 个答案:

答案 0 :(得分:2)

libname myMacros 'C:\temp';

option mstored sasmstore=mymacros;

%helloWorld()

这就是你需要做的所有事情 - 提醒SAS你指向的东西,然后运行宏。您不需要包含任何内容。