全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1058 5
2013-07-06
如果我想取下面的IP:后面的数字不要其他东西,如果用SAS读取数据呢,数据在txt相当不规则.  QQ 5231747,价钱可谈

以下只是部分数据


IP: 41.58.35.111 - DATE: Thursday 04 July 00:22:23 - [URL: /.php] | [Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit//537.36] \nIP: 41.58.35.104 - DATE: Thursday 04 July 00:22:43 - [URL: /administrator/images/common/Logon.aspx.php] | [Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36] \nIP: 41.58.35.104 - DATE: Thursday 04 July 00:22:43 - [URL: /administrator/images/common/confirm.aspx.php] | [Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36] \nIP: 41.58.35.104 - DATE: Thursday 04 July 00:23:03 - [URL: /administrator/images/common/confirm.aspx.php] | [Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36] \nIP: 41.58.35.104 - DATE: Thursday 04 July 00:23:10 - [URL: /administrator/images/common/confirm.aspx.php] | [Agent

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2013-7-6 07:27:58
好的
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-7-6 08:16:15
有时间的话,自己试着估计也能写出来的
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-7-6 08:40:22
我有一个思路,有兴趣可以参考下:
首先用列控制定位到IP:然后用4个整型变量分开存取IP或者干脆用正则表达式

以下内容摘自:The_Little_SAS_Book _3rd_Edition.pdf
可用于直接取IP:后的内容
The @‘character’ column pointer In section 2.9 we showed you how you can use the @
column pointer to move to a particular column before reading data. However, sometimes you
don’t know the starting column of the data, but you do know that it always comes after a particular
character or word. For these types of situations, you can use the @‘character’ column pointer. For
example, suppose you have a data file that has information about dog ownership. Nothing in the
file lines up, but you know that the breed of the dog always follows the word Breed:. You could
read the dog’s breed using the following INPUT statement:
INPUT @’Breed:’ DogBreed $;

SAS正则表达式下载地址:
SAS正则表达式

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-7-6 09:33:46
DATA  ffile;
   INFILE 'D:\log1.txt' LRECL=40000 DELIMITER="\" ;
   length name $ 25;
   INPUT name    @@;
RUN;

data ffile1;
set ffile;
start=find(name,":");
end=find(name,"-");
ip=substr(name,start+2,end-start-2);
run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-7-6 13:16:17
与楼上的思路是一样的。
DATA  ffile;
  INFILE 'F:\readhtmlyjt\log.txt' LRECL=40000 DELIMITER="\" ;
  length name  $25.;
  INPUT name   @@;
RUN;
data ffile1(keep=name ip);
set ffile;
retain flag;
  flag + 1;
  pattern2 = 's/:.+?-//s';
  retain pattern_id;
  pattern_id = prxparse(pattern2);
  /*正则表达式读取: -之间的内容*/
  CALL PRXSUBSTR(PATTERN_id,name,START,LENGTH);
  IF START GT 0 THEN DO;
  ip = SUBSTR (name,START+1,LENGTH-2);
  end;
run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群