I have a data set with IDs who have the following variables:
-a numeric variable we'll call "event" indicating event number (i.e. 1st event, 2nd event, etc.).
-a numeric variable we'll call "type" indicating event type (i.e. 1=fast, 2=slow, etc.).
-a numeric variable we'll call "cause" indicating cause of the event (i.e. 1=person 2=vehicle, etc.)
I am trying to code a variable that indicates the number of occurrences for that id with the same type and cause. So, the first appearance of that combination would be 1, the second 2, etc. I'll call this variable "same." My dataset is sorted by ID and date so "same" should reflect the first occurence of that type/cause combo, then the second and so on.
Sample code below showing what I have and what I want:
data have;
input id event type cause;
datalines;
1 1 1 1
1 2 1 2
2 1 2 2
3 1 1 2
3 2 2 1
3 3 2 1
3 4 1 2
3 5 1 2
3 6 1 1
4 1 1 1
4 2 1 1
;
RUN;
data want;
input id event type cause same;
datalines;
1 1 1 1 1
1 2 1 2 1
2 1 2 2 1
3 1 1 2 1
3 2 2 1 1
3 3 2 1 2
3 4 1 2 2
3 5 1 2 3
3 6 1 1 1
4 1 1 1 1
4 2 1 1 2
;
RUN;
Does this make sense?
As always, thanks to everyone for always helping out!
... View more