SAS Base (9)

The following SAS program is submitted:

data WORK.RETAIL;
Cost=’$20.000′;
Discount=.10*Cost;
run;

What is the result?

A. The value of the variable Discount in the output data set is 2000.No messages are written to the SAS log.
B. The value of the variable Discount in the output data set is 2000.A note that conversion has taken place is written to the SAS log.
C. The value of the variable Discount in the output data set is missing.A note in the SAS log refers to invalid numeric data.
D. The variable Discount in the output data set is set to zero.No messages are written to the SAS log.

Check Answer
Answer: C

注解:由于Cost是字符型变量,只有数值型变量才能参与数学运算,SAS会尝试将字符型转换成数值型,但由于Cost中有一个$,SAS无法完成类型转换。如果把$去掉,结果则会完全不同。

Leave a Reply

Your email address will not be published. Required fields are marked *