I do have a tricky one:
Here is my example data. It is sorted by a date variable (which is not included here). I want to calculate a a new variable, called seq_no which creates a grouping sequence number for each consecutive flagged records. The seq_no variable should look like in the example and I want to calculate it with SAS or SQL.
ID flag seq_no
1 Y 1
1
1 Y 2
1 Y 2
2
2 Y 1
2 Y 1
2
2 Y 2
3 Y 1
3 Y 1
3
Thanks a lot in advance! Stephan