SAS中文论坛

 找回密码
 立即注册

扫一扫,访问微社区

查看: 1446|回复: 3
打印 上一主题 下一主题

SAS advance exam question 4: Macro Variable

[复制链接]

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
楼主
 楼主| 发表于 2010-6-9 05:05:07 | 只看该作者

SAS advance exam question 4: Macro Variable

The following SAS program is submitted:
%let Value=9;
%let Add=5;
%let Newval=%eval(&Value/&Add);
%put &Newval;

What is the value of the macro variable Newval when the %PUT statement executes?
A. 0.555
B. 2
C. 1.8
D. 1

Why the correct answer is 1? What is the function of %eval ?

What if the following SAS codes is submitted?
%let Value=9;
%let Add=5;
%let Newval=&Value/&Add;
%put &Newval;

Is the value of the macro variable Newval  still 1 when the %PUT statement executes? Why?

Thanks in advance.
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
沙发
 楼主| 发表于 2010-6-9 13:27:20 | 只看该作者

Re: SAS advance exam question 4: Macro Variable

还容易考完了,再看这些题都要吐了,简单点说,就别考虑是否严谨了
这题的知识点是maroc的%eval()函数的用法
1 只能对整数执行计算,%eval(5+5.5)会报错
2 返回值也是个整数,计算出的小数部分自动就被截掉了,1.8就只省1了. 如果需要计算浮点数可以用%sysevalf()函数. %sysevalf(1/3.3)是OK的.
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
板凳
 楼主| 发表于 2010-6-10 21:22:07 | 只看该作者

Re: SAS advance exam question 4: Macro Variable

多谢
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
地板
 楼主| 发表于 2010-6-10 22:07:04 | 只看该作者

Re: SAS advance exam question 4: Macro Variable

21   %let Value=9;
22   %let Add=5;
23   %let Newval_1=%eval(&Value/&Add);
24   %put Newval_1 = &Newval_1;
Newval_1 = 1

25
26   %let Newval_2=%sysevalf(&Value/&Add);
27   %put Newval_2 = &Newval_2;
Newval_2 = 1.8

28
29   %let Newval_3=&Value/&Add;
30   %put Newval_3 = &Newval_3;
Newval_3 = 9/5

31   %let Value=9.1;
32   %let Add=5.1;
33   %let Newval_4=%eval(&Value/&Add);
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand
       is required. The condition was: 9.1/5.1
34   %put Newval_4 = &Newval_1;
Newval_4 = 1

35   %let Value=9.1;
36   %let Add=5.1;
37   %let Newval_4=%sysevalf(&Value/&Add);
38   %put Newval_4 = &Newval_1;
Newval_4 = 1

39   %let Newval_4=%eval(&Value+&Add);
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand
       is required. The condition was: 9.1+5.1
40   %put Newval_4 = &Newval_1;
Newval_4 = 1

41   %let Newval_4=%sysevalf(&Value+&Add);
42   %put Newval_4 = &Newval_1;
Newval_4 = 1
回复 支持 反对

使用道具 举报

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

本版积分规则

QQ|小黑屋|手机版|Archiver|SAS中文论坛  

GMT+8, 2026-2-4 05:03 , Processed in 0.177911 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表