我正在尝试寻找一种在7天的滚动期内联系客户超过3次的情况。因为我几乎使用SAS进行所有操作,所以我试图连接到oracle端并使用partition语句来获取所需的信息。我创建了一个测试方案以尝试使其正常工作,但目前它给了我“ Missing Keyword”错误,而且似乎看不到它所缺少的内容。
这是我的测试数据集:
data work.have;
input customer_id id call_date yymmdd10.;
format call_date yymmdd10.;
cards;
111 1111 2019-03-01
111 1112 2019-03-01
111 1113 2019-03-02
111 1114 2019-03-03
111 1115 2019-03-04
111 1116 2019-03-05
111 1117 2019-03-06
111 1118 2019-03-07
111 1119 2019-03-08
111 1120 2019-03-09
111 1121 2019-04-01
222 1122 2019-02-01
222 1123 2019-03-02
222 1124 2019-03-03
222 1125 2019-03-01
222 1126 2019-03-11
222 1127 2019-03-12
222 1128 2019-03-13
;
run;
这是我到目前为止的代码:
proc sql;
connect to oracle as test (user=&user. pw=&pass. path='path');
create table work.want as
select * from connection to test (
select id, call_date, customer_id, call_num
from (select id, call_date, customer_id,
count(id) over (partition by customer_id order by call_date range between interval 6 day preceding and current row) call_num
from work.have where call_date between '2019-02-22' and '2019-03-31' order by customer_id, id) t
where call_num >= 4
);
disconnect from test;
quit;
任何帮助将不胜感激。我希望我的眼睛变得模糊起来很容易。
答案 0 :(得分:1)
您在interval literal中缺少单引号:
引号不是可选的。因此必须是:
...
count(id) over (partition by customer_id order by call_date range between interval '6' day preceding and current row) call_num
---------^ ^
...