LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (April 2005, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
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 */


Back to: Top of message | Previous page | Main SAS-L page