Hi Peter,
>That sounds like replacing input strings or values with a randomly distributed ...
The values don't matter here, this is about methods of testing. Tested values or results could be strings in this case.
>This will be true when there are 4 tests for 1 function, and perhaps above 10:1.
I guess the threshhold is platform dependant.
Indeed. If a function is 10 times slower than a test, having more than 10 tests makes the function appealing again (and starts cluttering the data step too). As usual, one has to do one's home work depending on the particular circumstances. I suspect testing long strings would be more time consuming testing than short ones for example.
The main thing imho though, is that unless these tests are run millions of times, legibility matters most (whatever this means to each of us :o).
These runs give an overwhelming speed advantage to formats:
[pre]
%macro loop; * create a 2000-else-if test;
%do i=1 %to 2000;
else if A<&i then B=&i;
%end;
%mend;
data _null_; * 1 test before match 0.09s;
A=1;
do I=1 to 1e6;
if A<0 then B=1;
%loop
end;
run;
data _null_; * 1000 tests before match 7.2s;
A=1e3;
do I=1 to 1e6;
if A<0 then B=1;
%loop
end;
run;
%macro loop; * create a 2000-when test;
%do i=1 %to 2000;
when(&i) B=&i;
%end;
%mend;
data _null_; * select clause 17s;
A=1;
do I=1 to 1e6;
select(I);
%loop
otherwise;
end;
end;
run;
data _null_; * select clause 17s;
A=1e3;
do I=1 to 1e6;
select(I);
%loop
otherwise;
end;
end;
run;
proc format ; * create a 2000-entry format;
value test
%macro loop;
%do i=1 %to 2000;
&i="&i"
%end;
%mend;
%loop;
data _null_; * formats 0.09s;
A=1e3;
do I=1 to 1e6;
B=input(put(A,test.),32.);
end;
run;[/pre]