全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
5856 5
2011-03-31
路过的牛人请分析一下。多谢先。

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.
二维码

扫码加我 拉你入群

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

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

全部回复
2011-3-31 12:24:18
从别的网站上得到答案了,在这里和大家分享一下。30题因为有个comma,总是忘记这个,唉。33题numeric variable's default length should be N8, so max length can be 2**64-1
二维码

扫码加我 拉你入群

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

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

2011-3-31 13:36:07
好~~~~~~~~~~~~~~~~
二维码

扫码加我 拉你入群

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

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

2011-4-4 02:07:12
length 8 说的是字节byte,不是读入格式的width,informat w.d 中的w指的是列宽width。

“33题numeric variable's default length should be N8, so max length can be 2**64-1”

2**64-1表示的8位字节长度能存储的最大整数。
二维码

扫码加我 拉你入群

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

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

2017-2-27 14:36:05
atmosphere7 发表于 2011-3-31 12:24
从别的网站上得到答案了,在这里和大家分享一下。30题因为有个comma,总是忘记这个,唉。33题numeric varia ...
我亲自跑过SAS,第30题不是因为有个comma,而是因为where 条件语句里面的变量是不会根据需要自动转换的。
119  data test1;
120  length a $4.;
121  input a$;
122  cards;

NOTE: 数据集 WORK.TEST1 有 2 个观测和 1 个变量。
NOTE: “DATA 语句”所用时间(总处理时间):
      实际时间          0.01 秒
      CPU 时间          0.00 秒

125  ;
126  run;
127  data test2;
128  set test1;
129  where a>60;
ERROR: WHERE 子句运算符要求兼容的变量。
130  run;

NOTE: 由于出错,SAS 系统停止处理该步。
WARNING: 数据集 WORK.TEST2 可能不完整。该步停止时,共有 0 个观测和 1 个变量。
NOTE: “DATA 语句”所用时间(总处理时间):
      实际时间          0.10 秒
      CPU 时间          0.00 秒


二维码

扫码加我 拉你入群

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

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

2017-3-1 07:06:29
第30题,不是因为逗号。是因为:
”Can use WHERE statement when only specifying data set variables”。也就是说,在数据集里,只有文字的SALARY 变量。没有数字型的SALARY,所以报错。
二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群