楼主: atmosphere7
5449 5

[原创博文] SAS Base 50题中的30和33题疑问 [推广有奖]

  • 0关注
  • 0粉丝

高中生

17%

还不是VIP/贵宾

-

威望
0
论坛币
19 个
通用积分
0
学术水平
0 点
热心指数
1 点
信用等级
0 点
经验
319 点
帖子
27
精华
0
在线时间
13 小时
注册时间
2007-3-7
最后登录
2014-8-29

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
路过的牛人请分析一下。多谢先。

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

扫码加我 拉你入群

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

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

关键词:SAS base Base conversion Character converted conversion character 程序

沙发
atmosphere7 发表于 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

使用道具

藤椅
leafyoung 发表于 2011-3-31 13:36:07 |只看作者 |坛友微信交流群
好~~~~~~~~~~~~~~~~

使用道具

板凳
hongxx 发表于 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位字节长度能存储的最大整数。

使用道具

报纸
liushui 在职认证  发表于 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 秒


使用道具

地板
sherry123 发表于 2017-3-1 07:06:29 |只看作者 |坛友微信交流群
第30题,不是因为逗号。是因为:
”Can use WHERE statement when only specifying data set variables”。也就是说,在数据集里,只有文字的SALARY 变量。没有数字型的SALARY,所以报错。

使用道具

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

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-24 03:25