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 (November 2004, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Mon, 22 Nov 2004 11:28:35 -0500
Reply-To:   "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM>
Subject:   Re: Incremental counter

Moud, Kamyar wrote: > Hi All > > Can we have an incremental counter in SAS like "for loop" in VB for > certain observations of a variable (not the whole column)? Where can > I find quick simple example of it? Sample below). Thx >

Unlike VB, a data step has an implicit loop. The automatic variable _n_ tells you which iteration the implicit loops is in. When the implicit loop contains a SET statement, _n_ corresponds to the row number of the data set. { There are cases when the previous statement is not true, but those are cases you probably don't have to worry about right now }.

> for certain observations of a variable

Depending on the criteria, you might have

if _n_ in (6,10,12) then myCounter + 1; if _n_ > 16 then myCounter = .;

What is your definition of "certain" ?

-- Richard A. DeVenezia http://www.devenezia.com/


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