我在学习INFILE的时候遇到了这样一个问题。
具体例子如下。
Name - Survival Analysis
Authors - James Klein and Herman David
Number - 1739082
Inventory - 15
Price - $23.22
Discount - 13%
Name - Time Series
Authors - Peter Fader
Number - 2802005
Inventory - 17
Price - $51.22
Discount - 0.5%
这是附件中txt包含的内容。
data Books1;
INPUT @13 Name $20.;
INPUT @13 Authors $30.;
INPUT @13 Number @;
INPUT @13 SUB 2.;
IF SUB=17 Then LABEL='SCIENCE';
IF SUB=28 Then LABEL='FINANCE';
DROP SUB;
INPUT @13 Inventory;
INPUT @13 Price comma8.;
INPUT @13 Discount percent6.;
datalines;
Name - Survival Analysis
Authors - James Klein and Herman David
Number - 1739082
Inventory - 15
Price - $23.22
Discount - 13%
Name - Time Series
Authors - Peter Fader
Number - 2802005
Inventory - 17
Price - $51.22
Discount - 0.5%
run;
如果用datalines,这个程序可以运行。
如果不用,而是用
data Books1;
INFILE ‘address of books.txt’;
INPUT @13 Name $20.;
INPUT @13 Authors $30.;
INPUT @13 Number @;
INPUT @13 SUB 2.;
IF SUB=17 Then LABEL='SCIENCE';
IF SUB=28 Then LABEL='FINANCE';
DROP SUB;
INPUT @13 Inventory;
INPUT @13 Price comma8.;
INPUT @13 Discount percent6.;
run;
那么就会出错。
我个人感觉,当数据在txt中保存时,每一行结束时,后面不占column。所以,调用txt,定义name长度是20,会导致第一行没有足够的数据(不到20行),从而跑到第二行。但是很奇怪的事,第二行没有足够的数据,却可以写进去。
请问,这是什么原因?
补充:我可以用其他方法导入这个txt,用informat定义变量先。我是想问第二个code出错的原因是什么?