Dear SAS community,
I am having trouble counting and resetting the count with conditions and your help would be much appreciated.
Suppose that I have data below;
Subject / Year / Condition
A 1991 2
A 1992 2
A 1993 1
A 1994 2
A 1995 2
B 1990 1
B 1991 2
B 1992 1
B 1993 2
C 1991 2
C 1992 2
C 1993 2
C 1994 2
C 1995 1
I cannot change the order of this, and I would like to start counting
when first "1" appears and continue counting through "2" and reset each time "1" appears for the same individual.
so that it would give me:
A 1991 2 0
A 1992 2 0
A 1993 1 1
A 1994 2 2
A 1995 2 3
B 1990 1 1
B 1991 2 2
B 1992 1 1
B 1993 2 2
C 1991 2 0
C 1992 2 0
C 1993 2 0
C 1994 2 0
C 1995 1 1
How can I achieve this? Please help. Thank you!
Regards,
T