全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
6551 8
2010-08-03
悬赏 10 个论坛币 已解决
The following SAS program is submitted:
%let test = one;
%let one = two;
%let two = three;
%let three = last;
%put what displays is &&&&&test;
What is written to the SAS log?
(A) what displays is one
(B) what displays is two
(C) what displays is three
(D) what displays is last
请给出详细解释,顺便问下如果问题改为以下5个:
%put what displays is &&&test;
%put what displays is &&&&test;
%put what displays is &&&&&test;
%put what displays is &&&&&&test;
%put what displays is &&&&&&&test; (甚至更多&)将怎么解释,多谢,这个问题困扰我很久。

最佳答案

shmilyshmily 查看完整内容

5 个&的output是 two 基本规则是: 1.系统把2个&变成一个,前面四个& 变成 & & 2. 剩下&test 变成 one 到此系统得到的变量是 &&one 重复上面的步骤: 1. 将两个&变成一个,得到&one 所以最后结果是&one=two 从上面的分析可以看出 2n个&和n个&的效果是一样的 用这个小技巧做题的时候可以简化很多 根据这些规则楼主可以验证: 若有1,2,4,8,。。。个&,输出为one 3,5,6,9 。。。个&, 输出为two 7个&,输出为thre ...
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2010-8-3 05:12:28
5 个&的output是 two
基本规则是:
1.系统把2个&变成一个,前面四个& 变成 & &
2. 剩下&test 变成 one
到此系统得到的变量是 &&one
重复上面的步骤:
1. 将两个&变成一个,得到&one
所以最后结果是&one=two
从上面的分析可以看出 2n个&和n个&的效果是一样的 用这个小技巧做题的时候可以简化很多
根据这些规则楼主可以验证:
若有1,2,4,8,。。。个&,输出为one
3,5,6,9 。。。个&, 输出为two
7个&,输出为three
一下为SAS网站上找到的一个例子:
%put &&city&n;  /* correct */
If &N contains 6, when the macro processor receives this statement, it performs the following steps:
1.resolves && to &
2.passes CITY as text
3.resolves &N into 6
4.returns to the beginning of the macro variable reference, &CITY6, starts resolving from the beginning again, and prints the value of CITY6
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2010-8-3 06:17:47
5 个&的output是 two
基本规则是:
1.系统把2个&变成一个,前面四个& 变成 & &
2. 剩下&test 变成 one

到此系统得到的变量是 &&one

重复上面的步骤:
1. 将两个&变成一个,得到&one

所以最后结果是&one=two

从上面的分析可以看出 2n个&和n个&的效果是一样的 用这个小技巧做题的时候可以简化很多

根据这些规则楼主可以验证:
若有1,2,4,8,。。。个&,输出为one
3,5,6,9 。。。个&, 输出为two
7个&,输出为three

一下为SAS网站上找到的一个例子:
%put &&city&n;  /* correct */
If &N contains 6, when the macro processor receives this statement, it performs the following steps:

1.resolves && to &

2.passes CITY as text

3.resolves &N into 6

4.returns to the beginning of the macro variable reference, &CITY6, starts resolving from the beginning again, and prints the value of CITY6


希望对楼主有帮助。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2010-8-3 08:20:17
哈哈,谢谢2#,受教了!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2010-8-3 15:21:50
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2010-8-6 07:09:23
觉得解释的有些牵强----不同顺序是不一样的结果。
,2楼解释的是:&&&&&test->(&&)(&&)(&test)->(&&)(one)->&one=two
但有什么规则能按这样的顺序resolve?为什么不是其他顺序?比如&&&&test 为什么不是(&&)&(&test)->
&&one->(&&)one->&one->two????
回帖辛苦,谢谢,奖给你了。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群