我在考试试卷上有一个问题,询问SAS日志中的内容
%let test=one;
%let one=two;
%let two=three;
%let three=last;
%put what displays is &&&&&test;
Run Code Online (Sandbox Code Playgroud)
我很惊讶地发现,答案是: 2,因为我本来以为这将参考完全解析到最后.SAS也同意答案为两个.
任何人都可以解释一下SAS如何得出答案二,因为我读过的所有理论说明都表明宏处理器应该做到以下几点
小智 6
使用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
Run Code Online (Sandbox Code Playgroud)
从左到右,使用括号显示标记:
&&&&&test
(&&)(&&)(&test)
(&) (&) (one)
&&one
(&&)(one)
(&)(one)
&one
two
Run Code Online (Sandbox Code Playgroud)