Roger,
I want you test the following IML code if it would be faster than data step.
data have;
input id obs e1 e2 e3 b0 b1 b2 b3 b4 b5;
datalines;
2 2 1 2 3 600 0 200 0 530 550
2 1 1 2 3 600 0 200 0 530 550
3 3 2 2 3 150 500 . 120 3 58
3 2 2 2 3 150 500 . 120 3 58
3 1 2 2 1 150 500 . 120 3 58
4 3 1 2 3 200 300 550 270 0 50
4 2 1 2 3 200 300 550 270 0 50
4 1 1 2 3 200 300 550 270 0 50
5 1 1 2 . 20 20 200 100 500 57
5 2 1 2 . 20 20 200 100 500 57
5 3 1 2 . 20 20 200 100 500 57
;
run;
proc iml;
use have nobs nobs;
read all var {e1 e2 e3} into x;
read all var {b0 b1 b2 b3 b4 b5} into y;
close;
mode_e=j(nobs,1,.);
do i=1 to nobs;
temp=x[i,];
call tabulate(levels,freq,temp);
max_idx=loc(freq=freq[<>]);
want_idx=sample(max_idx,1);
mode_e[i]=levels[want_idx];
end;
mode_b=j(nobs,1,.);
do i=1 to nobs;
temp=y[i,];
call tabulate(levels,freq,temp);
max_idx=loc(freq=freq[<>]);
want_idx=sample(max_idx,1);
mode_b[i]=levels[want_idx];
end;
create mode var {mode_e mode_b};
append;
close;
quit;
data want;
merge have mode;
run;
proc print noobs;run;
... View more