t*****2 发帖数: 94 | 1 QUESTION
A raw data file is listed below:
---|---10---|---20---|----30
John McCloskey 35 71
June Rosesette 10 43
Tineke Jones 9 37
The following SAS program is submitted using the raw data file as input:
data work.homework;
infile 'file-specification';
input name $ age height;
if age LE 10;
run;
How many observations will the WORK.HOMEWORK data set contain?
A. 0 B. 2 C. 3
为什么答案是3个呢?我觉得读数据的时候就应该会出现ERROR呀, 即便不出现问题,
也只可能是2个呀。
求赐教! 先谢谢了! |
m*********n 发帖数: 413 | 2 the definition and the input of a variable are two different stories. In
this case there is no code error, and thus the data step was running. The
three variables therefore have been defined although you cannot read in
valid data. |
t*****2 发帖数: 94 | 3 但是这里问的是有多少个OBSERVATIONS,不是VARIABLES.
variable是有3个,但是observation用LE 10就可以剔除一个呀。
请指教! |
l***i 发帖数: 8 | 4 答案肯定是3个observations,因为后面的if语句对挑选几个observations不起作用。 |
h********o 发帖数: 103 | 5 This is LIST INPUT in which its default delimiter is blank. The data for AGE
variable are invalid since you define variable as numeric but you require
inputting charater values. So all three AGE values are set to missing and of
course less than or equal to 10. |
t*****2 发帖数: 94 | |
l***i 发帖数: 8 | 7 原来是这么个原因。我开始理解成,数据没读对,所以if没起作用呢。谢谢honglajiao
的解释! |
f******x 发帖数: 14 | 8 Nobody try? I tried, it gives me 2 obs. |
S******3 发帖数: 66 | 9 The key (考点)is: SAS will go to a new line when INPUT statement reached
past the end of a line without finding the specified delimiter. Here it
reads row 1 and row 2 as one record, so 3 is right. |
h********o 发帖数: 103 | 10 See output:
==============================
data test;
input name $ age height;
if age LE 10;
cards;
John McCloskey 35 71
June Rosesette 10 43
Tineke Jones 9 37
;
proc print data = test;
run;
==============================
Obs name age height
1 John . 35
2 June . 10
3 Tineke . 9 |
|
|
S******3 发帖数: 66 | 11 Ooops, I thought the 1st row of raw text file is "---|---10---|---20---|----
30"
【在 S******3 的大作中提到】![](/moin_static193/solenoid/img/up.png) : The key (考点)is: SAS will go to a new line when INPUT statement reached : past the end of a line without finding the specified delimiter. Here it : reads row 1 and row 2 as one record, so 3 is right.
|
c*****l 发帖数: 297 | 12 如果把IF 改成WHERE 就是0 了
【在 t*****2 的大作中提到】![](/moin_static193/solenoid/img/up.png) : QUESTION : A raw data file is listed below: : ---|---10---|---20---|----30 : John McCloskey 35 71 : June Rosesette 10 43 : Tineke Jones 9 37 : The following SAS program is submitted using the raw data file as input: : data work.homework; : infile 'file-specification'; : input name $ age height;
|
h********o 发帖数: 103 | 13 You must use IF statement when accessing raw data file using INPUT statement
. You can't use WHERE statement in this case otherwise SAS will generate
ERROR message. |
a*****9 发帖数: 1315 | 14 I tried , gives me 3 obs
data a
input name $ age height;
if age LE 10;
datalines;
John McCloskey 35 71
June Rosesette 10 43
Tineke Jones 9 37
;
proc print data=test;
run;
but couldn't figure out why ?
【在 f******x 的大作中提到】![](/moin_static193/solenoid/img/up.png) : Nobody try? I tried, it gives me 2 obs.
|
f******x 发帖数: 14 | 15 From your code, it will give you information:
OTE: Invalid data for age in line 5 6-14.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+
----7----+----8----+----9----+----0
5 John McCloskey 35 71
name=John age=. height=35 _ERROR_=1 _N_=1
NOTE: Invalid data for age in line 6 6-14.
6 June Rosesette 10 43
name=June age=. height=10 _ERROR_=1 _N_=2
NOTE: Invalid data for age in line 7 8-12.
7 Tineke Jones 9 37
name=Tineke age=. height=9 _ERROR_=1 _N_=3
Modify you code as:
data b;
input name $ 1-15 age height;
if age LE 10;
datalines;
John McCloskey 35 71
June Rosesette 10 43
Tineke Jones 9 37
;
proc print data=b; run;
Here is the result:
Obs name age
height
1 June Rosesette 10
43
2 Tineke Jones 9
37
【在 a*****9 的大作中提到】![](/moin_static193/solenoid/img/up.png) : I tried , gives me 3 obs : data a : input name $ age height; : if age LE 10; : datalines; : John McCloskey 35 71 : June Rosesette 10 43 : Tineke Jones 9 37 : ; : proc print data=test;
|