|
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/
|