You could try this - not tested - might have bugs. Here, I am calling your dataset 'stuff' and I'm calling your variables 'ID' (for the oo1, oo2... column) and 'value' for the 2nd column.
* make a row variable so that you can sort by ID (oo1, oo2, oo3 etc.)
without ruining the order of the integer variable (which I am calling 'value') ;
data stuff;
set stuff;
row=_N_;
run;
proc sort data=stuff; by id row; run;
proc sql noprint;
select max(nrows) into :maxrows from (select ID, count(*) as nrows from stuff group by ID);
quit;
* set to whatever value it is you are trying to identify between two matching values ;
%let SEARCHVAL=7;
data stuff;
length row 3;
set stuff (drop=row);
by id;
array T {&maxrows} _temporary_;
array f {&maxrows} _temporary_;
retain row 0;
if first.id then do;
call missing(of T[*], of f[*]);
x=0;
end;
x+1;
T[x]=value;
f[x]=0;
if last.id then do;
i=2;
do while(i<x);
i+1;
if T[i-2]=T[i] and T[i-1]=&SEARCHVAL then f[i-1]=1;
end;
do i=1 to x;
row+1;
value=T[x];
flag=f[x];
output;
end;
end;
keep row ID value flag;
run;
... View more