EDIT: To show an improved version of the earlier program. Here, after taking the 2-byte portions, put all together into a STRING- just taking not more than 50 bytes, using INDEX function we can search for the presence of '09' OR 'E8'. No need for 2 do-loops. data m2 m3;
set m1;
length dcp1 dcp2 dcp3 dc1 dc2 dc3 dc4 dc5 dc6 dc7 $2;
length STR $50;
dcp1 = d_c_p1;
dcp2 = d_c_p2;
dcp3 = d_c_p3;
dc1 = d_c1;
dc2 = d_c2;
dc3 = d_c3;
dc4 = d_c4;
dc5 = d_c5;
dc6 = d_c6;
dc7 = d_c7;
call catx(' ',STR, dcp1,dcp2,dcp3,dc1,dc2,dc3,dc4,dc5,dc6,dc7);
match = (index(STR, '09') | index(STR, 'E8'));
if match then output m3;
else output m2;
run; 1. You are taking 3 characters and comparing with 2 characters. I presume that you want 2 characters. 2. Assigning to a character variable of length 2 with your string will be faster than the use of SUBSTR() function. With these changes I placing the program below. This is not tested as your data set M1 is not known. Please test it and let the Community know about it. data m2 m3;
set m1;
length dcp1 dcp2 dcp3 dc1 dc2 dc3 dc4 dc5 dc6 dc7 $3;
dcp1 = d_c_p1;
dcp2 = d_c_p2;
dcp3 = d_c_p3;
dc1 = d_c1;
dc2 = d_c2;
dc3 = d_c3;
dc4 = d_c4;
dc5 = d_c5;
dc6 = d_c6;
dc7 = d_c7;
do i = dcp1, dcp2, dcp3;
if i = '09' then do;
Match1 = 1;
leave; * Early match ;
end;
end;
do i = dc1, dc2, dc3, dc4, dc5, dc6, dc7;
if i = 'E8' then do;
Match2 = 1;
leave; *Early Match;
end;
end;
if Match1 or Match2 then output m3;
else output m2;
run;
... View more