Hello everybody, I'd like to count flag by id and order and get the "target" as below. In summary, I want to put 1 when flag is 1 and add 1 when order increases. It shouldn't change when order is same. Could you help with solving this problem? id order flag target 1 1 0 0 1 1 0 0 1 2 0 0 1 2 0 0 1 2 1 1 1 3 0 2 1 3 1 1 1 4 0 2 1 4 0 2 1 5 0 3 1 5 0 3 1 6 0 4 1 6 0 4 2 1 0 0 2 1 0 0 2 2 0 0 2 2 0 0 2 2 1 1 2 3 0 2 2 3 0 2 2 4 1 1 2 4 0 1 2 5 0 2 2 5 0 2 2 5 0 2 data data01; input id order flag; datalines; 1 1 0 1 1 0 1 2 0 1 2 0 1 2 1 1 3 0 1 3 1 1 4 0 1 4 0 1 5 0 1 5 0 1 6 0 1 6 0 2 1 0 2 1 0 2 2 0 2 2 0 2 2 1 2 3 0 2 3 0 2 4 1 2 4 0 2 5 0 2 5 0 2 5 0 ; run;
... View more