Date: Tue, 26 Apr 2005 12:52:33 -0400
Reply-To: Chang Chung <chang_y_chung@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Chang Chung <chang_y_chung@HOTMAIL.COM>
Subject: Re: Cum Count
Hi, Lu,
Me again. I really meant this :-)
Cheers,
Chang
/* sample data */
data one;
input cust $ trans;
cards;
A 1234
A 2356
A 1356
A 1356
B 1456
B 3245
;
run;
/* if you want to count only the number of unique
trans values for each cust */
proc sort data=one out=sorted;
by cust trans;
run;
/* nested do until */
data three;
attrib cumm_trans label="serial number of unique trans within cust";
cumm_trans = 0;
do until (last.cust);
do until (last.trans);
set sorted;
by cust trans;
cumm_trans + last.trans;
end;
output;
end;
drop trans;
run;
proc print data=three;
var cust cumm_trans;
run;
/* on lst
cumm_
Obs cust trans
1 A 1
2 A 2
3 A 3
4 B 1
5 B 2
*/