首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >何时引用宏变量

何时引用宏变量
EN

Stack Overflow用户
提问于 2015-11-13 16:56:45
回答 1查看 169关注 0票数 3

在SAS中,在引用宏变量时,我看到有时代码在宏引用周围使用双引号,但其他时候,它引用没有引号的变量。

我什么时候应该在我的&之前使用引号,什么时候不使用?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-13 17:03:11

当您使用宏变量代替通常需要引用的硬编码非宏文本时,您只需要引用它们-通常在proc或数据步骤代码中。

代码语言:javascript
复制
%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));
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33697935

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档