0
我有一个数据集有ID,日期时间+一堆价值领域。所有记录在一小时内彼此
这个想法是,记录是在一个小时内彼此是一个会话。每24小时只能有一个会话。 (时间从第一条记录开始测量)
day()方法不起作用,因为一条记录可能是23:55 PM,而下一条可能是第二天12:01 AM,它会是同一届会议。
我添加的rowid和运行以下:
data testing;
set testing;
by subscriber_no;
prev_dt = lag(record_ts);
prev_row = lag(rowid);
time_from_last = intck("Second",record_ts,prev_dt);
if intck("Second",record_ts,prev_dt) > -60*60 and intck("Second",record_ts,prev_dt) < 0 then
same_session = 'yes';
else same_session = 'no';
if intck("Second",record_ts,prev_dt) > -60*60 and intck("Second",record_ts,prev_dt) < 0 then
rowid = prev_row;
else rowid = rowid;
format prev_dt datetime19.;
output;
run;
输入
ID record_TS rowid
52 17MAY2017:06:24:28 4
52 17MAY2017:07:16:12 5
91 05APR2017:07:04:55 6
91 05APR2017:07:23:37 7
91 05APR2017:08:04:52 8
91 05MAY2017:08:56:23 9
输入文件由ID和记录TS排序。
产量为
ID record_TS rowid prev_dt prev_row time_from_last same_session
52 17MAY2017:06:24:28 4 28APR2017:08:51:25 3 -1632783 no
52 17MAY2017:07:16:12 4 17MAY2017:06:24:28 4 -3104 yes
91 05APR2017:07:04:55 6 17MAY2017:07:16:12 5 3629477 no
91 05APR2017:07:23:37 6 05APR2017:07:04:55 6 -1122 yes
91 05APR2017:08:04:52 7 05APR2017:07:23:37 7 -2475 yes This needs to be 6
91 05MAY2017:08:56:23 9 05APR2017:08:04:52 8 -2595091 no
从底部
第二排 - ROWID出来7,而我需要它来为6
基本上我需要改变之前保存当前的rowid脚本移动以评估下一个脚本。
谢谢 本
我已经取得的成就,我需要
proc sql;
create table testing2 as
select distinct t1.*, min(t2.record_TS) format datetime19. as from_time, max(t2.record_TS) format datetime19. as to_time
from testing t1
join testing t2 on t1.id_val= t2.id_val
and intck("Second",t1.record_ts,t2.record_ts) between -3600 and 3600
group by t1.id_val, t1.record_ts
order by t1.id_val, t1.record_ts
;
quit;
但我仍然不知道是否有移动,以评估下一个前提交修改到当前行的方式行。
为什么不创建一个“会话”表中,有每个会话一个行定义的'ExpiresAt'日期是在未来24小时。然后,每当用户提出请求时,将'ExpiresAt'从现在开始更新为24小时。 – Basic
这就是我想要做的。我无法更改源表的结构或可用数据。 – Ben
您可以将您的HAVE数据(即输入数据集)添加到问题中吗? subscriber_no变量是什么打印在输出作为ID?我注意到你有一个'BY subscriber_no;'语句,但没有逻辑来阻止两个不同的用户被分配到同一个会话。通常,输入和输出数据集是相同的,即使只是测试,因为这会使得难以重复测试和检查结果。 – Quentin