SAS 宏引用如何与格式文字交互?
在干净的会话中本地执行:
%let x = %str(put(age, best.));
proc sql;
select &x from sashelp.class;
quit;
这会生成以下错误:
1 put(age, best.)
----
22
----
76
ERROR 22-322: Syntax error, expecting one of the following: a format name, ?.
ERROR 76-322: Syntax error, statement will be ignored.
但是这个“手动解析”版本运行时没有注释、警告或错误:
proc sql;
select put(age, best.) from sashelp.class;
quit;
有人可以准确解释 %str() 在此程序中执行的操作导致执行时出现问题?对于这个模糊的问题表示歉意,但我不确定相关的交互是什么;我无法使用等效的数据步骤语法进行复制,因此可能涉及 proc SQL 特性?
Executing locally in a clean session:
%let x = %str(put(age, best.));
proc sql;
select &x from sashelp.class;
quit;
This generates the following error:
1 put(age, best.)
----
22
----
76
ERROR 22-322: Syntax error, expecting one of the following: a format name, ?.
ERROR 76-322: Syntax error, statement will be ignored.
But this "manually-resolved" version runs without notes, warnings or errors:
proc sql;
select put(age, best.) from sashelp.class;
quit;
Can somebody explain exactly what %str() is doing in this program that causes an issue at execution time? Apologies for the vague question, but I am unsure what the relevant interactions are; I cannot replicate using equivalent data-step syntax so perhaps proc SQL peculiarities are involved?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
%str() 函数在宏编译期间屏蔽字符串。删除let语句中的%str()函数或在sql select中添加%unquote()函数以正确解析if。
The %str() function masks a character string during macro compilation. Remove the %str() function in the let statement or add an %unquote() function in the sql select to have if resolve correctly.
回答于 runsubmit.com 上的这个问题:
Answered at this question on runsubmit.com:
您可以使用格式语句来代替吗?例如,这工作得很好。
Can you use a format statement instead? For example, this works just fine.
出于某种原因,SAS 不喜欢“最好的”。格式。
即当我尝试这个时,你的代码有效
???
For some reason SAS doesn't like the "best." format.
i.e. when I try this, your code works
????
如果将其添加到代码中,
您将在日志中看到 &x 如何被 %str 引用。这就是 proc sql 代码不起作用的原因。在 proc sql 语句的选择部分使用 %Unquote 将允许代码运行。
http://www2.sas.com/proceedings/forum2007/152-2007.pdf
If you add this to your code
you will see how &x is quoted by %str, in the log. That is why the proc sql code doesn't work. Using %Unquote in the select portion of the proc sql statement will allow the code to run.
http://www2.sas.com/proceedings/forum2007/152-2007.pdf