SAS 宏引用如何与格式文字交互?

发布于 2024-11-16 13:59:56 字数 645 浏览 4 评论 0原文

在干净的会话中本地执行:

%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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

翻身的咸鱼 2024-11-23 13:59:56

%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.

秉烛思 2024-11-23 13:59:56

回答于 runsubmit.com 上的这个问题

我将把这个答案标记为
正确,因为它引导我到此页面
文档数量:
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#tw3514-unquote.htm
- “在极少数情况下,使用宏引用功能屏蔽文本会改变方式
单词扫描仪标记文本
...扫描仪这个词不使用它
作为文字标记的边界
输入堆栈”。听起来像是一个错误,
坦率地说,但是如果分词器
算法和我一样古老和毛茸茸的
想象一下,我也会把它当作一个怪癖!

Answered at this question on runsubmit.com:

I'm going to mark this answer as
correct because it led me to this page
of documentation:
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#tw3514-unquote.htm
- "In rare cases, masking text with a macro quoting function changes the way
the word scanner tokenizes the text
... The word scanner does not use it
as the boundary of a literal token in
the input stack". Sounds like a bug,
frankly, but if the tokenizer
algorithm is as ancient and hairy as I
imagine, I'd spin it as a quirk too!

用心笑 2024-11-23 13:59:56

您可以使用格式语句来代替吗?例如,这工作得很好。

%let x = %str( age format=best.);

proc sql;
    select &x. from sashelp.class;
quit;

Can you use a format statement instead? For example, this works just fine.

%let x = %str( age format=best.);

proc sql;
    select &x. from sashelp.class;
quit;
单调的奢华 2024-11-23 13:59:56

出于某种原因,SAS 不喜欢“最好的”。格式。

即当我尝试这个时,你的代码有效

 %let x = %str(put(age, 8.));

???

For some reason SAS doesn't like the "best." format.

i.e. when I try this, your code works

 %let x = %str(put(age, 8.));

????

白色秋天 2024-11-23 13:59:56

如果将其添加到代码中,

%put _user_ ;

您将在日志中看到 &x 如何被 %str 引用。这就是 proc sql 代码不起作用的原因。在 proc sql 语句的选择部分使用 %Unquote 将允许代码运行。

http://www2.sas.com/proceedings/forum2007/152-2007.pdf

If you add this to your code

%put _user_ ;

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文