提问人:ruhi 提问时间:11/11/2023 最后编辑:Richardruhi 更新时间:11/12/2023 访问量:42
SAS 宏取消引用
SAS Macro Dereferencing
问:
声明了以下宏变量:
%let x=2;
%let y=3;
%let x3=4;
%let y2=5;
%let x2=6;
%let y3=7;
%let m=x;
%let n=y;
取消引用后将评估什么:
i.&&&m&y - &&&n&y
ii.&&&m&x&&&n&y
答:
4赞
Tom
11/12/2023
#1
你可以运行它来找到答案。
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
上一个:LibreOffice Calc 输入框和数学表达式
下一个:在宏中捕获单态泛型
评论