声明了以下宏变量:
%令x=2;
%让 y=3;
%让x3=4;
%让 y2=5;
%令x2=6;
%让 y3=7;
%让 m=x;
%让n=y;
以下解除引用将评估什么: i.&&&m&y - &&&n&y ii.&&&m&x&&&n&y `
您只需运行它即可找到答案。
1 %let x=2;
2 %let y=3;
3 %let x3=4;
4 %let y2=5;
5 %let x2=6;
6 %let y3=7;
7 %let m=x;
8 %let n=y;
9
10 %put i. &&&m&y - &&&n&y ;
i. 4 - 7
11 %Put ii. &&&m&x&&&n&y ;
ii. 67
当宏处理器看到 && 时,它会将其转换为 & 并提醒自己,它需要再次传递结果以进一步解析宏变量引用。因此,在 &&&m&y 的第一遍中,它将 && 转换为 &,将 &m 转换为 x,&y 转换为 3。然后,当它返回处理结果时,它将 &x3 转换为 4。
您可以打开 SYMBOLGEN 并查看它的运行情况。
12
13 options symbolgen;
14 %put i. &&&m&y - &&&n&y ;
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable M resolves to x
SYMBOLGEN: Macro variable Y resolves to 3
SYMBOLGEN: Macro variable X3 resolves to 4
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable N resolves to y
SYMBOLGEN: Macro variable Y resolves to 3
SYMBOLGEN: Macro variable Y3 resolves to 7
i. 4 - 7
15 %Put ii. &&&m&x&&&n&y ;
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable M resolves to x
SYMBOLGEN: Macro variable X resolves to 2
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable N resolves to y
SYMBOLGEN: Macro variable Y resolves to 3
SYMBOLGEN: Macro variable X2 resolves to 6
SYMBOLGEN: Macro variable Y3 resolves to 7
ii. 67