楼主: MiSH2HK
4731 11

[问答] 关于SAS ADV 63题中的第29题,局部与全局宏变量区别 [推广有奖]

  • 0关注
  • 1粉丝

VIP1

大专生

36%

还不是VIP/贵宾

-

威望
0
论坛币
2022 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
382 点
帖子
35
精华
0
在线时间
39 小时
注册时间
2015-2-1
最后登录
2016-12-23

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
The following SAS program is submitted:

%let Mv=shoes;
%macro PRODUCT(Mv=bicycles);
%let Mv=clothes;
%mend;

%PRODUCT(Mv=tents)
%put Mv is &Mv;

What is written to the SAS log?


A.
Mv is bicycles

B.
Mv is clothes

C.
Mv is shoes

D.
Mv is tents

答案是:C。

为什么题目改成

%letMv=shoes;

  %macro PRODUCT(td=bicycles);  

     %let Mv=clothes;  

     %let td=opp;

  %mend;     

  %PRODUCT(td=tents)   

  %put Mv is &Mv;


答案就是clothes呢? 区别在哪里啊???谢谢各位!



二维码

扫码加我 拉你入群

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

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

关键词:全局宏变量 following Product clothes written following clothes written shoes

沙发
cccccccjjjjjjjj 发表于 2016-4-27 00:49:17 |只看作者 |坛友微信交流群
我来回答吧。 不知道对不对
要知道他的位置顺序 local, global

第一题:
里面都是在local,macro结束local就没了,就只有global=shoes 在。

第二题:是macro:shoes  td的都是local 然后clothes 会把shoes覆盖 因为一开始sas看没有local就去看有没有global 发现有一个global在外面那个

谢谢了!!!!

使用道具

藤椅
l1i2n3i4n5g 在职认证  发表于 2016-4-27 09:15:27 |只看作者 |坛友微信交流群
当一个全局宏变量的名称已经存在时,
如果在某个宏内定义了相同名称的宏变量(不是用%LOCAL语句创建,也不是宏参数),
该操作只相当于对这个已经存在的全局宏变量重新进行了赋值。

使用道具

板凳
MiSH2HK 发表于 2016-4-27 13:59:21 |只看作者 |坛友微信交流群
cccccccjjjjjjjj 发表于 2016-4-27 00:49
我来回答吧。 不知道对不对
要知道他的位置顺序 local, global
宏会先去找局部变量,然后再去找全局变量?

第一个程序:%let MV=shoes, 这个是全局变量,所以就不考虑局部变量了

第二个程序:%let MV=shoes; 这个不是全局变量么? 难道变成局部变量了?

使用道具

报纸
MiSH2HK 发表于 2016-4-27 13:59:56 |只看作者 |坛友微信交流群
l1i2n3i4n5g 发表于 2016-4-27 09:15
当一个全局宏变量的名称已经存在时,
如果在某个宏内定义了相同名称的宏变量(不是用%LOCAL语句创建,也不 ...
请问你是在针对第二个程序么

使用道具

地板
L_SAS 发表于 2016-4-28 01:37:44 来自手机 |只看作者 |坛友微信交流群
我也不明白这个问题。Adv pre guide(4th)P391:If the macro procesor receives either a %Let statement or a macro variablereference(&macro) in open code,it checks only the global symbol table for existence of the macro variable.

使用道具

7
七月maranda 发表于 2016-4-28 04:17:19 |只看作者 |坛友微信交流群
顶贴求资源

使用道具

8
rendajingguan01 发表于 2016-4-28 10:35:14 |只看作者 |坛友微信交流群
L_SAS 发表于 2016-4-28 01:37
我也不明白这个问题。Adv pre guide(4th)P391:If the macro procesor receives either a %Let statement o ...
这句话的意思是

在open code中,创建的只能是globle 变量,所以,不会check local symbol table

其实也好理解吧

使用道具

9
rendajingguan01 发表于 2016-4-28 11:10:45 |只看作者 |坛友微信交流群
我看了半天,说说我的理解。

第一段代码中,定义mcro时候,参数中已经定义了一个local 的 Mv,
所以,mcro中的 %let Mv = clothes;更新的是mcaro 中的 local 的Mv
这个理解 来自于下面的第一步。

你可以试试%put 放到 macro中,就会发现有两个Mv 变量,一个global,一个local。


第二段代码中,mcro 中没有定义 local 的 Mv,只是更新  Mv,所以,值被更新了。


以下是我的依据,注意加粗部分,

Suppose the macro processor receives a %LET statement during a macro call, as follows:
%let macvar=value;The macro processor processes the following steps:

1.The macro processor checks to see whether the macro variable macvar already exists in the local symbol table. If so, the macro processor updates macvar in the local symbol table with the value value. If macvar does not exist in the local table, the macro processor goes on to step 2.

2.The macro processor checks to see whether the macro variable macvar already exists in the global symbol table. If so, the macro processor updates macvar in the global symbol table with the value value. If macvar does not exist in the global symbol table, the macro processor goes on to step 3.

3.The macro processor creates a macro variable named macvar in the local symbol table and assigns a value of value to it.

使用道具

10
rendajingguan01 发表于 2016-4-28 11:25:02 |只看作者 |坛友微信交流群
我加了 %put 在mcro中的结果

1    %let Mv=shoes;
2    %macro PRODUCT(Mv=bicycles);
3    %let Mv=clothes;
4    %put _user_;
5    %mend;
6

7    %PRODUCT(Mv=tents)

PRODUCT MV clothes
GLOBAL MV shoes

8    %put Mv is &Mv;

Mv is shoes

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-27 17:33