路过的牛人请分析一下。多谢先。
Q30 我的疑问---关于auto conversion of character-to-numeric variable:
当character variable和一个numeric value比较时,auto conversion will happen,
为什么这里不行?
when a character variable compared to a numeric value, the character
variable will be auto-converted to numberic variable --- from SAS base Prep
Guide P402
以下程序我在sas上试过了,的确是d,但不明白为什么这里不自动转换。
Q30.The descriptor and data portions of the Work.Salaries data set are shown
below.
Variable Type Len Posname Char 8 0
salary status Char 8 Char 8 16 8
name status salary
Liz S 15,600
Herman S 26,700
Marty S 35,000
The following SAS program is submitted: proc print data=work.salaries; where
salary<20000; run; What is displayed in the SAS log after the program is
executed?
a. A NOTE indicating that 1 observation is read.
b. A NOTE indicating that 0 observations were read.
c. A WARNING indicating that character values have been converted to numeric
values.
d. An ERROR indicating that the WHERE clause operator requires compatible
variables.
Correct answer: d
Salary is defined as a character variable. Therefore, the value in the WHERE
statement must be the character value 20,000 enclosed in quotation marks.
************************
Q33 我的疑问---numeric和character variable的default length都是8 characters
(http://www.sfu.ca/sasdoc/sashtml/lrcon/z1103996.htm). 为什么33题中"mlgrams2"结果不被truncate?
Q33.The following SAS program is submitted: data test; input animal1
$ animal2 $ mlgrams1 mlgrams2; cards; hummingbird ostrich 54000.39 90800000
.87 ; run; Which one of the following represents the values of each variable
in the output data set
a. animal1 animal2 mlgrams1 mlgrams2
hummingb ostrich 54000.39 90800000
b. animal1 animal2 mlgrams1 mlgrams2
hummingb ostrich 54000.39 90800000.87
c. animal1 animal2 mlgrams1 mlgrams2
hummingbird ostrich 54000.39 90800000
d. animal1 animal2 mlgrams1 mlgrams2
hummingbird ostrich 54000.39 90800000.87
Correct answer: b
The CARDS statement is an alias for the DATALINES statement. In the INPUT
statement, you must specify a dollar sign ($) after the variable name in
order to define a character variable. If you do not specify otherwise, the
default storage length for a variable is 8. In the example above, the
character value hummingbird is truncated to hummingb.