SAS-定义包含未定义宏变量的宏变量而不生成警告

SAS-定义包含未定义宏变量的宏变量而不生成警告,sas,Sas,如何定义包含对尚未定义的其他宏变量引用的宏变量而不生成警告 考虑一个为不同变量生成类似图的程序。根据变量的不同,每个地物的标签都会发生变化。由于除了特定的分析变量外,所有图形都有类似的标签,因此将标签放在程序顶部以便于修改是有意义的。问题是,在程序中的这一点上,变量名尚未定义 /*Top of program*/ %let label = This %nrstr(&thing) gets defined later.; %put &=label; /* ... */ /*L

如何定义包含对尚未定义的其他宏变量引用的宏变量而不生成警告


考虑一个为不同变量生成类似图的程序。根据变量的不同,每个地物的标签都会发生变化。由于除了特定的分析变量外,所有图形都有类似的标签,因此将标签放在程序顶部以便于修改是有意义的。问题是,在程序中的这一点上,变量名尚未定义

/*Top of program*/
%let label = This %nrstr(&thing) gets defined later.;
%put &=label;

/* ... */

/*Later in program*/
%let thing = macro variable;
%put &=label;
例如:

/*Top of program*/
%let label = This &thing gets defined later.;

/* ... */

/*Later in program*/
%let thing = macro variable;
%put &=label;
这将产生所需的输出:

LABEL=This macro variable gets defined later.
但它也会在日志中生成警告:

WARNING: Apparent symbolic reference THING not resolved.
如果我将
%nrstr
放在
和thing
的周围,则
标签的形式是正确的(即
标签=此&thing稍后定义。
),但是
和thing
在定义后不再解析

/*Top of program*/
%let label = This %nrstr(&thing) gets defined later.;
%put &=label;

/* ... */

/*Later in program*/
%let thing = macro variable;
%put &=label;
这将产生:

LABEL=This &thing gets defined later.
LABEL=This &thing gets defined later.

有什么方法可以避免将警告写入日志吗?

这里是理解
%STR
类型引用和
%QUOTE
类型引用之间区别的地方

%QUOTE
及其变体在宏执行时屏蔽文本,而
%STR
及其变体在宏编译时屏蔽文本。在本例中,您关心的是后者,而不是前者,因为您希望在执行过程中解决
&thing
,而不是在编译过程中

所以这是救援行动的
%NRSTR
。您还需要使用
%UNQUOTE
来获取宏变量以完全解析-即,取消
NRSTR

/*Top of program*/
%let label = This %nrstr(&thing.) gets defined later.;

/* ... */

/*Later in program*/
%let thing = macro variable;
%put %unquote(&label);
只需在数据步骤中使用CALL SYMPUTX()来定义宏变量

data _null_;
  call symputx('label','This &thing gets defined later.');
run;
/*Later in program*/
%let thing = macro variable;
%put &=label;