SAS中文论坛
标题:
求助数据读取问题
[打印本页]
作者:
shiyiming
时间:
2008-12-11 19:52
标题:
求助数据读取问题
有如下形式的txt文件形式:要求部分读取如下内容,遇到#Fields:时便读取信息,其他信息不用读取,请教高手如何写代码?
#Software: Microsoft Internet Information Services 6.0
#Version: 1.0
#Date: 2008-07-18 10:53:21
#Fields: date time s-sitename s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) sc-status sc-substatus sc-win32-status
2008-07-18 10:53:21 W3SVC1246049203 72.15.206.27 GET /default.asp - 80 - 72.15.206.27 Mozilla/4.0+(compatible;+MSIE+7.0;+Windows+NT+5.2;+.NET+CLR+1.1.4322;+.NET+CLR+2.0.50727) 200 0 0
#Software: Microsoft Internet Information Services 6.0
#Version: 1.0
#Date: 2008-07-18 10:55:19
#Fields: date time s-sitename s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) sc-status sc-substatus sc-win32-status
2008-07-18 10:55:19 W3SVC1246049203 72.15.206.31 GET /default.asp - 80 - 72.15.206.31 Mozilla/4.0+(compatible;+MSIE+7.0;+Windows+NT+5.2;+.NET+CLR+1.1.4322;+.NET+CLR+2.0.50727) 200 0 0
2008-07-18 10:55:19 W3SVC1246049203 72.15.206.31 GET /favicon.ico - 80 - 72.15.206.31 Mozilla/4.0+(compatible;+MSIE+7.0;+Windows+NT+5.2;+.NET+CLR+1.1.4322;+.NET+CLR+2.0.50727) 404 0 2
2008-07-18 10:55:32 W3SVC1246049203 72.15.206.31 GET /default.asp - 80 - 72.15.206.31 Mozilla/4.0+(compatible;+MSIE+7.0;+Windows+NT+5.2;+.NET+CLR+1.1.4322;+.NET+CLR+2.0.50727) 200 0 0
2008-07-18 10:57:08 W3SVC1246049203 72.15.206.31 GET /default.asp - 80 - 72.15.206.31 Mozilla/4.0+(compatible;+MSIE+7.0;+Windows+NT+5.2;+.NET+CLR+1.1.4322;+.NET+CLR+2.0.50727) 200 0 0
2008-07-18 10:57:23 W3SVC1246049203 72.15.206.31 GET /Default.asp - 80 - 210.74.133.34 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+2.0.50727) 200 0 0
2008-07-18 10:57:47 W3SVC1246049203 72.15.206.31 GET /default.asp - 80 - 210.74.133.34 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+2.0.50727) 200 0 0
#Software: Microsoft Internet Information Services 6.0
#Version: 1.0
#Date: 2008-07-18 18:32:58
#Fields: date time s-sitename s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) sc-status sc-substatus sc-win32-status
2008-07-18 18:32:58 W3SVC1246049203 72.15.206.31 GET /Default.asp - 80 - 24.91.118.22 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+1.1.4322;+.NET+CLR+2.0.50727) 200 0 0
2008-07-18 18:39:13 W3SVC1246049203 72.15.206.31 GET /Default.asp - 80 - 24.91.118.22 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+1.1.4322;+.NET+CLR+2.0.50727) 200 0 0
#Software: Microsoft Internet Information Services 6.0
#Version: 1.0
#Date: 2008-07-18 19:02:25
#Fields: date time s-sitename s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) sc-status sc-substatus sc-win32-status
2008-07-18 19:02:25 W3SVC1246049203 72.15.206.31 GET /Default.asp - 80 - 24.91.118.22 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+1.1.4322;+.NET+CLR+2.0.50727) 200 0 0
作者:
shiyiming
时间:
2008-12-12 06:50
标题:
Re: 求助数据读取问题
[code:9z854kjm]
options validvarname=any;
data temp;
infile 'pathto\log.txt' end=eof;
retain re;
if _n_=1 then
re = prxparse('/^\d\d\d\d-\d\d-\d\d$/');
input @1 type $;
if type='#Fields:' then do;
input @1 datestr:$10. @;
do until(eof or not prxmatch(re, datestr));
date = input(datestr, yymmdd10.);
input time:time8.
's-sitename'n:$15.
's-ip'n:$15.
'cs-method'n:$10.
'cs-uri-stem'n:$255.
'cs-uri-query'n:$10.
's-port'n:$5.
'cs-username'n:$20.
'c-ip'n:$15.
'cs(User-Agent)'n:$255.
'sc-status'n:3.
'sc-substatus'n:1.
'sc-win32-status'n:1.
;
output;
if not eof then input @1 datestr:$10. @;
end;
end;
format date yymmdd10. time time8.;
drop type datestr;
run;
[/code:9z854kjm]
其实您最好手工做,经济危机的根本在生产力过剩。
我的意思是说,您最好把每段数据都拷贝到另一个文本文件里,然后再用那IMPORT WIZARD。这样比较稳妥。
作者:
shiyiming
时间:
2008-12-12 09:57
标题:
Re: 求助数据读取问题
完全看不出TXT怎么断的行,想帮也帮不上忙。
作者:
shiyiming
时间:
2008-12-15 20:20
标题:
Re: 求助数据读取问题
谢谢高手,非常感谢,能告诉我你的邮箱么?有空跟你学习一下??
欢迎光临 SAS中文论坛 (https://mysas.net/forum/)
Powered by Discuz! X3.2