有
%SYMEXIST(macro-var-name)
宏函数查看宏变量是否存在,但不能写入
%IF
在露天,所以你必须把你的
%IF
语句在其他宏中。您可能最终会编写一个宏,只是为了将代码包装在如下所示的源文件中。这不是很漂亮,但如果需要警卫的话,你也许能挺过去。
%macro wrapper;
%if %symexist(foo_defined) %then %return;
%macro foo;
%global foo_defined;
%let foo_defined = 1;
%put i am foo;
%mend foo;
%mend wrapper;
%*-- tests --*;
options mcompilenote=all;
%symdel foo_defined;
%*-- first time it will define %foo --*;
%wrapper
%foo
/* on log
NOTE: The macro FOO completed compilation without errors.
6 instructions 108 bytes.
i am foo
*/
%*-- second time it will not --*;
%wrapper
%foo
/* on log
(no notes on macro compilation)
i am foo
*/
在调用时,SAS提供了一组目录、文件和目录,用于访问(编译/未编译)宏。这使得直接查明给定宏名称的宏是否已经可用于此会话非常麻烦,但并非不可能。阅读本文中的(血腥)详细信息:
http://support.sas.com/resources/papers/proceedings09/076-2009.pdf