Hello, I have a challenge seemingly requiring a DO UNTIL-type operation which I am having trouble getting to work. What I have is a data set with multiple users, each with 1 or more records. I want to sum up successive rows for each user, resetting the sum once it reaches a certain amount. So, just as an example: data program; input user $ value; datalines; 1 9 1 12 1 18 1 15 1 7 1 4 1 3 ; run; My desire is to create a new variable (call it simply "count"), essentially the number of successive rows which add up to less than 30. So, the first row (with value 9) would have a count value of 1; the second row (with value 12) would have a count value of 2 (since 9 + 12 = 21 < 30); the third row wouldhave a count value of 1 (since 9 + 12 + 18 = 39 > 30, forcing it to reset to 1); the fourth row (with value 15) would again have a count value of 1 (since 18 + 15 = 33 > 30, forcing another reset to 1); the fifth row (with value 7) would have a count value of 2 (since 15 + 7 = 22 < 30); the sixth row (with value 4) would have a count value of 3 (since 15 + 7 + 4 = 26 < 30); the seventh row (with value 3) would have a count value of 4 (since 15 + 7 + 4 + 3 = 29 < 30); and the next row's count would reset to 1 unless its value were 0. If at any point it hits a new user ID, the count variable automatically outputs and resets to 0, and the process begins again for the next user. I am unsure how to make this work; I cannot seem to get DO UNTIL to iterate over successive rows in the data set. Of course, if there is another way to do this without using DO UNTIL, I'm all ears. Thanks in advance for any assistance!
... View more