10. The following SAS program issubmitted:
data WORK.RETAIL;
Cost=‘$20,000′;
Discount=.10*Cost;
run;
What is the result?
A. Thevalue of the variable Discount in the output data set is 2000.No messages arewritten to the SAS log.
B. The value of the variable Discount in the outputdata set is 2000.A note that conversion has taken place is written to the SASlog.
C. The value of the variable Discount in the outputdata set is missing. A note in the SAS log refers to invalid numeric data.
D. The variable Discount in the output data set is setto zero.No messages are written to the SAS log.
这个题非常地狡猾~
【相关知识点】numeric -character 以及 character - numeric variable 的自动转化
【答案】C
【解释】正常情况下,numeric和 character variable是可以相互自动转化的;但是当SAS 试图把character 换成numeric的时候,$ 阻止了这一进程。
【同类题对比】
The following SAS program is submitted:
data work.retail;
cost = '20000';
total = .10 * cost;
run;
Which one of the following is the value of thevariable TOTAL in the output data set?
A. 2000
B. '2000'
C. . (missing numeric value)
D. ' ' (missing character value)
【答案】A 这里并没有$,SAS 于是自己进行了自动转化
【模拟程序】
1)没有$-变了!
data test;
a=200;
b='abc';
b=a;
run;
proc print;
run;
2)有$-木有变
data test;
a='$200';
b=10*a;
run;
proc print;
run;
【补充知识】numeric和character 的相生相爱
l Character – numeric 自动转换
1. Character– numeric 自动转换的条件,
当这个charactervariable:
1)被分配给一个本来被定义为numericvariable
2)被用在一个计算式子中 (如上面的同类题对比)
3)和一个number variable相比较的时候
Eg: if height >= weight;
4) 被用在一个需要numeric variable 的方程式子中
Eg:age=sum(weight,height)
2. Theautomatic conversion
1)使用 w.d 形式
2)将会生成一个numeric性质的missingvalue,如果这个character variable 没有使用numeric的标准标记法
| Character | automatic | Numeric |
| 12.47 | => | 12.47 |
| -8.96 | => | -8.96 |
| 1.243E1 | => | 12.43 |
| 1,742.64 | => | . |
3. 特殊情况
“Where statement”不会帮你自动转换,因为他傻
4. 因为麻烦或者各种意想不到的情况可能发生,还是乖乖非自动转化的方程吧!
Input(source, informat) -> source 指的是the charactervariable
Eg: Salary=input(payrate,2.)*hours;
l Numeric - Character 自动转换
1. 自动转化的条件:
当这个 numericcharacter被:
1)被分配给一个本来被定义为character的 variable
2)被用在一个需要character variable的operator 里
3)被用在一个需要character variable的 function 里
Eg: Region=substr(site,1,4);
2. 手动转化
Put(source,format) -> source代表需要被转化的numericvariable,常数,或者表达式。



雷达卡




京公网安备 11010802022788号







