全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
3516 5
2016-03-03
求各位大神帮我看一下下面这道题:

80. The following SAS program is submitted:
%let rc = Begin;
%macro test;
data out;
set sashelp.prdsale nobs = totalobs;
if totalobs > 10 then do;
%let rc = high;
end;
else do;
%let rc = low;
end;
run;
%mend;
%let rc = Before Execution;
%test

The data set SASHELP.PRDSALE has 50 observations.
What is the value of the variable RC when the macro finishes execution?
A.low
B.high
C.Begin
D.Before Execution

Answer: A

我想,它的运行顺序及宏变量的定义形式应该是: %let rc=Begin; ------Global
                                                                       %let rc=Before Execution; ------Global
                                                                       %test; (在这里rc会被赋值成high或low) ------Local
因为SASHELP.PRDSALE有50条observation,带到程序中后,50>10,那么%let rc = high,但是为什么答案会是A(low)呢??

十分不解,在此请各位大侠帮忙答疑解惑![em49] 多谢多谢!![em44]
二维码

扫码加我 拉你入群

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

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

全部回复
2016-3-3 13:51:32
50>10%let rc = high为local宏变量
global中&rc的值是宏编译时生成的%let rc=low
二维码

扫码加我 拉你入群

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

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

2016-3-3 22:42:09
谢谢您的回复! 可是,依然不是很明白,“50>10%let rc = high为local宏变量”——这个没问题,可是,“global中&rc的值是宏编译时生成的%let rc=low”——这个就不懂了!  %macro test难道不是local吗? 还有,当50>10的时候,运行到%let rc=high的时候不就终止了吗??
多谢多谢![em49]
二维码

扫码加我 拉你入群

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

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

2017-1-27 16:25:43
Amandanannn 发表于 2016-3-3 22:42
谢谢您的回复! 可是,依然不是很明白,“50>10%let rc = high为local宏变量”——这个没问题,可是,“glo ...
我来告诉你,这题你没注意的是if不是%if哦,else也是,所以执行时是忽略他们的,所以rc不断地被赋值Global,从begin-high-low揪出来了
二维码

扫码加我 拉你入群

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

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

2018-7-10 03:34:18
hftz3326 发表于 2017-1-27 16:25
我来告诉你,这题你没注意的是if不是%if哦,else也是,所以执行时是忽略他们的,所以rc不断地被赋值Globa ...
一语道破~ 谢谢!
二维码

扫码加我 拉你入群

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

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

2018-11-26 01:23:12
hftz3326 发表于 2017-1-27 16:25
我来告诉你,这题你没注意的是if不是%if哦,else也是,所以执行时是忽略他们的,所以rc不断地被赋值Globa ...
我也在这道题上纠结了很久。。。万分感谢~~~~我又把%put放到不同位置试了一下,分享我run的结果...

3286  %let rc = Begin;
3287  %put the value of RC at the begining is &rc;
the value of RC at the begining is Begin

3288  %macro test;
3289  data out;
3290  set sashelp.prdsale nobs = totalobs;
3291  if totalobs > 10 then do;
3292  %let rc = high;
3293  end;
3294  %put the value of RC in marco before else do is &rc;
3295  else do;
3296  %let rc = low;
3297  end;
3298  run;
3299  %put the value of RC in marco before mend is &rc;
3300  %mend;
3301  %put the value of RC after mend is &rc;
the value of RC after mend is Begin

3302
3303  %let rc = Before Execution;
3304
3305  %put the value of RC before call is &rc;
the value of RC before call is Before Execution

3306  %test
the value of RC in marco before else do is high

NOTE: There were 1440 observations read from the data set SASHELP.PRDSALE.
NOTE: The data set WORK.OUT has 1440 observations and 10 variables.
NOTE: DATA statement used (Total process time):
      real time           0.07 seconds
      cpu time            0.06 seconds


the value of RC in marco before mend is low3307  %put the value of RC after call is &rc;
the value of RC after call is low


二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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