全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
2365 3
2008-11-10

怎样计算如下格式的数据的用户的登陆时长
操作类型中01表示登陆,02表示下线,操作时间20080701073549 则表示2008年7月1号7点35分49秒

终端类型可以不考虑.


号码        操作类型 终端类型 操作时间
727095283 01 1204 20080701073549
727095283 02 1204 20080701074058
727095283 01 1204 20080701081754
726676742 02 1101 20080701113438
726676742 01 1101 20080701134932
727095283 02 1204 20080701122809
727095283 02 1204 20080701144822
726676742 01 1101 20080701075635
726676742 02 1101 20080701084341
726676742 01 1101 20080701084344
726676742 02 1101 20080701085941
726676742 02 1101 20080701091553
726676742 01 1101 20080701091502
727095283 01 1204 20080701122256
726676742 01 1101 20080701092055
726676742 01 1101 20080701092857
726676742 02 1101 20080701092857
726676742 01 1101 20080701095528
726676742 02 1101 20080701095528
726676742 01 1101 20080701101253
726676742 02 1101 20080701101204
726676742 01 1101 20080701101421

有几个问题值得考虑,由于统计周期的限制,有些用户只有登陆行为数据,没有下线行为数据。
该如何使登陆时长的计算不考虑这些数据啊?(注这个数据集大约有500万条记录啊,所以会有点麻烦啊!)
谢谢各位大侠了啊?


二维码

扫码加我 拉你入群

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

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

全部回复
2008-11-10 15:33:00
没有下线行为数据,那这次登入是否算登入。没有下线行为数据,如果不算的话,比较好处理。自己写个程序跑下就出来了。
二维码

扫码加我 拉你入群

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

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

2008-11-10 23:38:00
你的统计周期是多长, 24hrs  or 一周 or 更长? 如果是一天, 讷么用01's 24:00作为cut-off point, 如果你找不到相应的02.

另外的一种方法就是impute. 分类找到这些客户,回填the missing values.
二维码

扫码加我 拉你入群

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

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

2008-11-11 05:30:00

no comments but hope it is clear enough.

proc sort data = rawdata;

by id operate_time type ;

 

data good (drop = lag_type type rename = (operate_time = end_time)) need_work1 need_work2;

format start_time datetime.;

set rawdata ;

by id operate_time type;

lag_type = lag(type);

start_time = lag(operate_time);

if first.id then do;

      lag_type = '';

      start_time = .;

end;

if lag_type = '01' and type = '02' then do;

    format stay time.;

      stay = (operate_time - start_time) ;

    output good;

end;

else if (first.id and type = '02')

     or (type = lag_type) then output need_work1;

else if (last.id and type = '01') then output need_work2;

run;

 

data done_work (keep = id start_time end_time notes);

set need_work1(in = a) need_work2 (in = b);

by id operate_time type;

format notes $ 20. end_time datetime.;

 

if lag_type in ( '', '02') and type = '02' then do;

      notes = 'Missing Start Time';

      end_time = operate_time;

      start_time = .;

end;

 

else if lag_type = '01' and type = '01' then do;

      notes = 'Missing End Time';

end;

 

if b then do;

      notes = 'Non Closed Session';

      start_time = operate_time;

end;

 

run;

 

proc sort data = done_work;

by id start_time;

 

 

data final;

set good (in = g) done_work;

by id start_time;

if g then notes = 'Good Data';

run;

二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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