在SAS中,在引用宏变量时,我看到有时代码在宏引用周围使用双引号,但其他时候,它引用没有引号的变量。
我什么时候应该在我的&之前使用引号,什么时候不使用?
发布于 2015-11-13 17:03:11
当您使用宏变量代替通常需要引用的硬编码非宏文本时,您只需要引用它们-通常在proc或数据步骤代码中。
%let text = Hello;
/*You need quotes here*/
data _null_;
put "&text";
run;
/*Otherwise you get an error, because SAS thinks hello is a variable name*/
data _null_;
put &text;
run;
/*If you already have quotes in your macro var, you don't need to include them again in the data step code*/
%let text2 = "Hello";
data _null_;
put &text2;
run;
/*In macro statements, everything is already treated as text, so you don't need the quotes*/
%put &text;
/*If you include the quotes anyway, they are counted as part of the text for macro purposes*/
%put "&text";
/*When you are calling functions via %sysfunc that normally
require a variable name or a quoted string, you don't need quotes*/
%let emptyvar=;
%put %sysfunc(coalescec(&emptyvar,&text));https://stackoverflow.com/questions/33697935
复制相似问题