OK. The code is short .
/************* here pick up the minimal value of t_purchase, and data like : id ... min 1 .... '01jan2010:10:10:02'dt 1 .... '01jan2010:10:10:02'dt 1 .... '01jan2010:10:10:02'dt **************/ proc sql;
create table temp as
select *,min(t_purchase) as min
from have
group by id,opt;
quit;
DATA work.WANT;
if _n_=1 then do;
if 0 then set WORK.temp;
declare hash h(dataset: 'WORK.temp', hashexp:20); /* Here push table temp into Hash Table for querying later key is ID OPT T_PURCHASE */
h.definekey('id', 'opt', 't_purchase');
h.definedone();
end;
set WORK.temp;
COUNT_purchase=0; /*for each obs, reset count number to be 0*/
do i=MIN to t_purchase; /*for each obs, do loop from min to current t_purchase,step is one second*/
/* in Hash Table ,find whether there is an obs or not according to key id,opt,i(i.e. t_purchase) if find it,then count +1 */ if h.check(key:id, key:opt, key:i)=0 then COUNT_purchase+1;
end;
drop i;
run;
... View more