SAS simple row count -



SAS simple row count -

i have big info set has states included, looking @ ne. looking @ each state individually , want count number of rows included in each state. using:

record_num = _n_;

but gives me row count of first row ne included. example, row 49752 first record_num:

49752 49753 49754 49756 49757 49758

i want:

1 2 3 4 5 6

i want equal 1 instead. do:

record_num=_n_; num = record_num-49751;

but don't want alter code every time alter state alter record_num.

sas by-group processing need using.

for example:

data want; set have; state; if first.state counter=0; counter+1; run;

what when state changes, lastly record before alter has variable last.state set 1 (otherwise has 0), , next record (the first new value of state) has variable first.state set 1 (otherwise 0).

so set counter 0 each time new state encountered, , increment (var+1; increments variable , retains across rows).

if want have actual count, vasja notes in comments, add together if last.state; before run (which give 1 row per state, lastly one).

count sas

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -