SAS中文论坛

标题: 求助:为什么我读入不了数据? [打印本页]

作者: shiyiming    时间: 2008-1-21 16:43
标题: 求助:为什么我读入不了数据?
想从一个txt文本上读入数据,比如数据是这样:

2006-01-13 978.81 -0.50
2006-01-16 961.44 -1.77
2006-01-17 964.29 0.30
2006-01-18 983.62 2.00
2006-01-19 991.22 0.77
2006-01-20 993.34 0.21

保存在aa.txt上,
我的程序是:

data stock.;
infile 'C:\aa.txt' ;
length date $10.;
input date  price  rate;
run;
proc print;
run;

结果是:

  Obs       date       price    rate

   1     2006-01-13      .        .
   2     2006-01-18      .        .

也就是后面两个变量是空值,并且只显示两个记录,这是为什么?

谢谢!
作者: shiyiming    时间: 2008-1-22 03:34
标题: Re: 求助:为什么我读入不了数据?
[code:2aethnr8]data stock.;[/code:2aethnr8]

What is the point (.) doing there?

[code:2aethnr8]data kuhasu;
infile "'C:\Documents and Settings\A\桌面\1.txt" ;
informat date yymmdd10. ;
informat price best12.;
informat rate best12.;
format date yymmdd10.;
format price best12.;
format rate best12.;
input date price rate;
run;
proc print;
run;[/code:2aethnr8]
作者: shiyiming    时间: 2008-1-22 09:19
标题: Re: 求助:为什么我读入不了数据?
楼主大概是想建一个library名叫stock,但是忘了写libname语句和stock.后面跟的dataset的名称了,呵呵呵。

superkuhasu,你看得真仔细,我就没有一眼看出来还有这个错。
作者: shiyiming    时间: 2008-1-22 10:45
标题: Re: 求助:为什么我读入不了数据?
谢谢!不过我还有一个疑问,就是我从其他软件上导出的txt文件,数据之间好像不是空格,比如下面这段数据,
000006        20061208        11.36       
000006        20061211        11.97       
000006        20061212        11.85       
000006        20061213        11.95       
000006        20061214        12.40       
000006        20061215        13.14       
000006        20061218        14.12       
怎样才能读入呢?
我用下面的程序读不出后面的数据。
data sasuser.aa;
infile 'C:\Documents and Settings\yanjiu\桌面\stock\aa.txt';
informat code $6.;
informat date yymmdd8.;
informat price best12.;
format date yymmdd8.;
format price best12.;
input code  @8 date  @17 price;
run;
作者: shiyiming    时间: 2008-1-22 11:26
标题: Re: 求助:为什么我读入不了数据?
data sasuser.aa;
infile 'C:\Documents and Settings\yanjiu\桌面\stock\aa.txt' delimiter="09"x;
informat code $6.;
informat date yymmdd8.;
informat price best12.;
format date yymmdd8.;
format price best12.;
input code @8 date @17 price;
run;

是分隔符吧,如果还是不行,在文本里将变量之间的分隔符统一替换成较明显的字符如“|”或“&”再设置delimiter=""选项
作者: shiyiming    时间: 2008-1-22 13:21
标题: Re: 求助:为什么我读入不了数据?
多谢了,可以了, <!-- s:D --><img src="{SMILIES_PATH}/icon_biggrin.gif" alt=":D" title="Very Happy" /><!-- s:D -->
作者: shiyiming    时间: 2008-1-22 13:22
标题: Re: 求助:为什么我读入不了数据?
顺便问一下,&quot;09&quot;x什么意思?
作者: shiyiming    时间: 2008-1-22 13:47
标题: Re: 求助:为什么我读入不了数据?
&quot;09&quot;x=tab
ASCII




欢迎光临 SAS中文论坛 (https://mysas.net/forum/) Powered by Discuz! X3.2