Hello all, I have a dataset that looks like this:; ID Month Right Left 1 1 10 5 1 2 11 6 1 3 8 10 2 1 7 10 2 2 8 10 2 3 8 11 3 1 7 7 3 1 10 7 I'd like to add a flag for each user showing whether right or left is higher. If right and left start as equal, I'd like it to check at the second month and check which is higher there. So, I'd like the result to look like this (note that the flag stays the same even if right/left switch later on, see ID 1, Month 3): ID Month Right Left right flag leftflag 1 1 10 5 1 . 1 2 11 6 1 . 1 3 8 10 1 . 2 1 7 10 . 1 2 2 8 10 . 1 2 3 8 11 . 1 3 1 7 7 1 . 3 1 10 7 1 . So far, I can get the flags to show up for the first month, looking like this: data result; set result; if month = 1 and (right > left) then rightflag = 1; if month = 1 and (left > right) then leftflag = 1; run; ID Month Right Left right flag leftflag 1 1 10 5 1 . 1 2 11 6 . . 1 3 8 10 . . 2 1 7 10 . 1 2 2 8 10 . . 2 3 8 11 . . 3 1 7 7 . . 3 1 10 7 . . I'd like to know how I can get that flag to fill in for all rows having the same ID, and how to implement the "move to second month" check if right = left at month 1. Thank you!
... View more