然后将单个客户的交易时间,交易金额2,以及序号,转置成两张表,并计算出这个客户交易的总条数
proc transpose data=cust_trans out=tmp_time;
by cust_id;
var datetime;
run;
proc transpose data=cust_trans out=tmp_xh;
by cust_id;
var xh;
run;
proc transpose data=cust_trans out=tmp_fee;
by cust_id;
var fee;
run;
proc sql noprint;
select count(*) as cnt into:cnt from cust_trans;
quit;
接着把这三张表合并
data tmp_result;
merge tmp_time tmp_xh tmp_fee;
by cust_id;
%do i=1 %to %eval(&cnt.-1);
%do j=2 %to &cnt.;
if -86400<time&i.-time&j.<86400 and fee&i.+fee&j.=0 then do;
xh&i.=xh&i.*0;
xh&j.=xh&j.*0;
fee&i.=fee&i.*0;
fee&j.=fee&j.*0;
end;
%end;
%end;
%do i=1 %to &cnt.;
if xh&i.>0 then do;
xh=xh&i.;
output;
end;
%end;
keep cust_id xh;
run;