Almost the same as the previous answer, but this vill list the first 3 varables, if 3 or more consecutive variables have the same value.
If this happens more than once in the same row, every set of first-three is output with the same value og obs. If the leave statement is uncommented, only the first set is output.
Obs is the input row number, not a variable from the input data set. To get the value from a variable in the input data set, just omit obs= _N_.
data have;
input (st1-st7)(3.);
cards;
1 2 4 4 5 6 6
8 9 10 10 10 13 14
15 16 17 17 19 21 21
22 23 25 24 24 24 26
40 41 42 42 42 43 46
10 10 10 12 11 11 11
;
data want (keep=obs st_numb);
length obs 8 st_numb $100;
set have;
array a _numeric_;
do i = 2 to dim(a);
if a{i} = a{i-1} then equals + 1;
else equals = 0;
if equals = 2 then do;
obs= _N_; st_numb = catx(' ',vname(a{i-2}), vname(a{i-1}), vname(a{i}));
output;
*leave;
end;
end;
run;
... View more