全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
7061 19
2011-09-15
1.The following SAS program is submitted:
%macro one(input);
%two
%put the value is &date;
%mend;
%macro two;
data _null_;
call symput('date', '12SEP2008');
run;
%mend;
%let date = 31DEC2006;
%one(&date)
What is the result when the %PUT statement executes?
A.A macro variable DATE with the value 12SEP2008 is retrieved from the global symbol table.
B.A macro variable DATE with the value 31DEC2006 is retrieved from the global symbol table.
C.A macro variable DATE with the value 12SEP2008 is retrieved from the local symbol table for the ONE macro.
D.A macro variable DATE with the value 12SEP2008 is retrieved from the local symbol table for the TWO macro.

Answer: A

2.The following SAS program is submitted:
%macro one(input);
%two
%mend;
%macro two;
data _null_;
call symputx('date', '12SEP2008', 'L');
run;
%put the value is &date;
%mend;
%let date = 31DEC2006;
%one(&date)
What is the result when the %PUT statement executes?
A.A macro variable DATE with the value 12SEP2008 is retrieved from the global symbol table.
B.A macro variable DATE with the value 31DEC2006 is retrieved from the global symbol table.
C.A macro variable DATE with the value 12SEP2008 is retrieved from the local symbol table for the ONE macro.D.A macro variable DATE with the value 12SEP2008 is retrieved from the local symbol table for the TWO macro.

Answer: D

3.
%macro one(input);
%two
%mend;
%macro two;
data _null_;
call symputx('date', '12SEP2008', 'G');
run;
%put the value is &date;
%mend;
%let date = 31DEC2006;
%one(&date)
What is the result when the %PUT statement executes?
A.A macro variable DATE with the value 12SEP2008 is retrieved from the global symbol table.
B.A macro variable DATE with the value 12SEP2008 is retrieved from the local symbol table for the ONE macro.
C.A macro variable DATE with the value 12SEP2008 is retrieved from the local symbol table for the TWO macro.
D.A macro variable DATE with the value 31DEC2006 is retrieved from the local symbol table for the TWO
macro.
Answer: A

小弟初学SAS,看不懂,请帮忙解释一下这几道题,多谢!!

二维码

扫码加我 拉你入群

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

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

全部回复
2011-9-15 08:46:05
期待高人的回答~~~
二维码

扫码加我 拉你入群

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

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

2011-9-16 06:48:10
求高人指导!!
二维码

扫码加我 拉你入群

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

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

2013-4-14 21:21:32
求解啊!!
二维码

扫码加我 拉你入群

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

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

2013-7-20 12:36:05
第一题:先查找是否存在该变量,查找顺序是由内而外,一旦找到该变量就进行更新。如果查找完都没找到,就在该语句所处最近的local table中创建该变量并赋值。
第二题和第三题:symputx中第三个参数是symbol table的意思,L代表local table,G代表global,F含义和第一题一样。
二维码

扫码加我 拉你入群

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

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

2014-12-3 04:56:19
第一题
我认为, 调用%one(&date)时,由于%one本身带local macro variable, 所以SAS 要先建个local symbol table来放local macro variable的值(假设这是新session, 所以以前没有local symbol table)。%one(&date)里面的%two就用到执行

%macro two;
data _null_;
call symput('date', '12SEP2008');
run;
%mend;

由于已经有了local symbol table, 所以call symput('date', '12SEP2008');就给date赋值12SEP2008并保存在local symbol table。(只有在local symbol table存在时才能使用call symput('date', '12SEP2008');)
最后%let date = 31DEC2006;是创建global macro variable 并把值 31DEC2006保存在global symbol table。
至此, 虽然有同名的两个变量date, 但一个保存在local symbol table,一个保存在global symbol table。

而%put the value is &date;是在macro definition 里面, 所以是local, 所以显示12SEP2008。

如果我说的对, 那个答案就是错的。
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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