05-17-2012 02:37 PM
If I have a sorted table like this:
INPUT fruit $40.;
I would like to add the "Count" column like this:
I know that I have to do something like this, I can't get it quite right.
Count = _N_;
Any help would be greatly appreciated.
05-17-2012 11:50 PM
Assuming your dataset has already sorted before.
DATA myfruit; INPUT fruit $40.; DATALINES; APPLE APPLE APPLE PEACH PEACH ; RUN; data myfruit; set myfruit; if fruit ne lag(fruit) then count=0; Count+1; run;