Posting the code you have (using the little-running-man icon) would allow us to suggest code that fixes what you have, instead of posting something new.
x needs to be incremented each second time that the value of y changes. So, you need to retain: x, the last value of y and another variable, i call it c holding the number of changes.
data want;
set have;
retain x c _y;
if _n_ = 1 then do;
x = 1;
c = 0;
end;
else do;
if _y ne y then do;
c = c + 1;
if c = 2 then do;
x = x + 1;
c = 0;
end;
end;
end;
_y = y;
run;
... View more