在SAS中,在引用宏变量时,我发现有时代码在宏引用周围使用双引号,但有时候,它引用没有引号的变量。
我什么时候应该在我和我之前使用引号?什么时候不应该?
答案 0 :(得分:4)
当您使用宏变量代替通常需要引用的硬编码非宏文本时,您只需要引用宏变量 - 通常在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));