I have a SAS data set, which I have sorted according to my needs. I want to split it into BY groups and, for each group, output each observation until the first occurrence of a particular value in a particular column.
ID No C1 Year2 C3 Date (DD/MM/YYYY) --------------------------------------------------------- AB123 4 B4 2008E OC 09/04/2008 AB123 3 B4 2008E EL 09/04/2008 AB123 2 B4 2008E ZZ 09/04/2008 AB123 1 B4 2008E OC 09/04/2008 AB123 0 B4 2008E ZZ 09/04/2008 AB123 1 B4 2008E OC 06/02/2008 AB123 0 B4 2008E ZZ 06/02/2008
This is one BY group: the data set is grouped by ID, C1, Year2 and sorted by ID, C1, Year2, Date(desc), No(desc). Further instances of each of ID, C1 and Year2 could occur anywhere in the data set, but the 3 variables define each BY group.
I want to output all observations per BY group up to and including the first occurrence of ZZ in C3. So above I would want the first 3 observations output (or flagged) and then move on to the next BY group.
Any help would be greatly appreciated. Please let me know if you need any more details of the problem. Thanks.
Here’s one way that should work.