```Date: Mon, 7 Oct 2002 11:42:44 -0400 Reply-To: "Chakravarthy, Venky" Sender: "SAS(r) Discussion" From: "Chakravarthy, Venky" Subject: Re: How to count? Comments: cc: "Jinrui.Cui@cshs.org" Content-Type: text/plain; charset="iso-8859-1" David Parent's solution is correct as it is. The sum statement COUNT + 1, simply adds to the accumulator variable COUNT. By definition, there is an automatic retain. Here is another solution using the DOW. If you want to preserve the order of variables as in the incoming dataset, uncomment the commented line. data temp; input @1 x \$1. @2 y \$1.; cards; A4 A6 A7 B8 B9 C1 run; data temp2 ; * if 0 then set temp ; do count = 1 by 1 until ( last.x ) ; set temp ; by x ; output ; end ; run ; Venky #****************************************# # E-mail: swovcc@hotmail.com # # Phone: (734) 622-1963 # #****************************************# -----Original Message----- From: Cui, Jinrui [mailto:Jinrui.Cui@cshs.org] Sent: Friday, October 04, 2002 6:21 PM To: SAS-L@LISTSERV.UGA.EDU; Parent, David Subject: RE: How to count? I just say to add "retain count", like > Data temp2; > Set temp; retain count; > By x; > /*Reset count to zero for each "x group"*/ > If first.x then count=0; > Count+1; > Run; > John > ---------- > From: Parent, David[SMTP:david.parent@CAPITALONE.COM] > Reply To: Parent, David > Sent: Friday, October 04, 2002 3:00 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Re: How to count? > > Hi Kit, > > If your data is not already sorted by x, sort it first. Then you could > use: > > Data temp2; > Set temp; > By x; > /*Reset count to zero for each "x group"*/ > If first.x then count=0; > Count+1; > Run; > > Regards, > David Parent > > -----Original Message----- > From: Kit Leung [mailto:hello_joecool@HOTMAIL.COM] > Sent: Friday, October 04, 2002 5:35 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: How to count? > > data temp; > input @1 x \$1. @2 y \$1.; > cards; > A4 > A6 > A7 > B8 > B9 > C1 > ; > run; > > Here's what I want to do: Basically, I need to set a counter to count how > many records under the same variable X. > X Y Count > A 4 1 > A 6 2 > A 7 3 > B 8 1 > B 9 2 > C 1 1 > . > . > run; > > > _________________________________________________________________ > Send and receive Hotmail on your mobile device: http://mobile.msn.com > > ************************************************************************** > The information transmitted herewith is sensitive information intended > only > for use by the individual or entity to which it is addressed. If the > reader > of this message is not the intended recipient, you are hereby notified > that > any review, retransmission, dissemination, distribution, copying or other > use of, or taking of any action in reliance upon this information is > strictly prohibited. If you have received this communication in error, > please contact the sender and delete the material from your computer. > ************************************************************************** The information transmitted herewith is sensitive information intended only for use by the individual or entity to which it is addressed. If the reader of this message is not the intended recipient, you are hereby notified that any review, retransmission, dissemination, distribution, copying or other use of, or taking of any action in reliance upon this information is strictly prohibited. If you have received this communication in error, please contact the sender and delete the material from your computer. ```

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