data T;
input ID L EXP;
Datalines;
A1 1 10
A1 1 10
A1 2 20 A1 2 20
A1 4 20
A1 4 20
A1 5 20
A2 1 10
A2 2 60
A2 2 60
A2 3 60
A2 3 60
A2 5 50 A2 7 50
A3 2 60
A3 4 60
;
data want;
do until (last.id);
set T;
by id;
if l <= 1 then flag = 1;
end;
put flag=;
do until(last.id);
set T;
by id;
if not first.id and lag(l) ne l - 1 then flag = 0;
if not flag then exp = 0;
output;
end;
drop flag;
run;
Hi,
On this dataset (already sorted by ID, L) , I want to update EXP to 0 in these cases:
1. The First.L per ID is not 1 (and all the subsequent to it)
2. The first time the sequence of L is broken per ID and all the subsequent to it. (there are repetitions of L)
i.e the output should be
A1 1 10 A1 1 10 A1 2 20
A1 2 20
A1 4 0 A1 4 0 A1 5 0 A2 1 10 A2 2 60 A2 2 60 A2 3 60 A2 3 60 A2 5 0
A2 7 0 A3 2 0 A3 4 0
The above code does not properly work in this case.
How should be amended?
Thanks.
... View more