我在考试试卷上有一个问题,询问SAS日志中的内容
%let test=one;
%let one=two;
%let two=three;
%let three=last;
%put what displays is &&&&&test;
我很惊讶地发现答案是:两个,因为我认为此引用将完全解析为最后。 SAS也同意答案是两个。
任何人都可以解释一下SAS如何得出答案 2 ,因为我读过的所有理论说明都表明宏处理器应该执行以下操作
答案 0 :(得分:5)
使用symbolgen选项可以帮助查看日志中发生的事情:
1 options symbolgen;
2 %let test=one;
3 %let one=two;
4 %let two=three;
5 %let three=last;
6
7 %put what displays is &&&&&test;
SYMBOLGEN: && resolves to &.
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable TEST resolves to one
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable ONE resolves to two
what displays is two
从左到右,使用括号显示代币:
&&&&&test
(&&)(&&)(&test)
(&) (&) (one)
&&one
(&&)(one)
(&)(one)
&one
two