Given the contents of the raw data file TYPECOLOR.DAT:
—-+—-10—+—-20—+—-30
daisyyellow
The following SAS program is submitted:
data FLOWERS;
infile ‘TYPECOLOR.DAT’ truncover;
length
Type $ 5
Color $ 11;
input
Type $
Color $;
run;
What are the values of the variables Type and Color?
A. Type=daisy, Color=yellow
B. Type=daisy, Color=w
C. Type=daisy, Color=daisyyellow
D. Type=daisy, Color=
注解:The code neither specified where to read the value of each variable nor the delimiter. SAS will start to read value from left to right, using the default delimiter, space(‘ ‘). SAS reads the first value ‘daisyyellow’ and assigns it to variable ‘Type’. As the length of ‘Type’ is 5 which means it can only hold up to 5 characters, the value is truncated to ‘daisy’. Then SAS tries to read the second value for ‘Color’, but there is nothing left in the file. SAS simply sets the value to missing.
One of the proper way to read the file would be telling SAS the position of each variable:
data FLOWERS;
infile ‘TYPECOLOR.DAT’;
length
Type $ 5
Color $ 11;
input
Type $ 1-5
Color $ 6-11;
run;
Obs | Type | Color |
1 | daisy | yellow |
If you were not sure the length of the second variable, TRUNCOVER option would be handy. It enables you to read variable-length records when some records are shorter than the INPUT statement expects.
The following program will produce the identical result, except that the value of ‘Color’ could be any length from 0 to 15.
data FLOWERS;
infile ‘TYPECOLOR.DAT’ truncover;
length
Type $ 5
Color $ 11;
input
Type $ 1-5
Color $ 6-20;
run;
为什么只到59题呢。看不到后面好着急。
我也好想看接下去的接待。比起crackman。我更喜歡Harrison的解答。 >_<
求发60-70.
Harrison棒棒,支持求發60-70
我也更喜欢Harrison的解答,支持求发60-70!呼唤Harrison!谢谢Harrison!
Harrison’s answer is very easy to understand, which is very helpful to SAS beginners. Thank you very much! Looking for the 60th-70th answers.
我也觉得你解释的比crackman好得多 简明又清楚
Please post 60-70! Thank you!!!!
any post after question 58?