shanshan199216 发表于 2017-7-20 09:22 
只是标出123这种就可以了,不用累加,可能我打错了,
proc import datafile='c:/sas/test1.xls' out=test;
run;
proc sort data=test out=sort_test1;
by party_id t;
run;
proc sort data=test out=sort_test2(keep=party_id t) nodupkey;
by party_id t;
run;
data ntest;
set sort_test2;
by party_id t;
if first.party_id then n=0;
if first.t then do until(last.t);
n+1;
end;
run;
proc sql;
create table final_test as
select a.*,b.n from
(sort_test1 as a
left join
ntest as b
on a.party_id=b.party_id and a.t=b.t);
quit;