@polingjw: Thanks for the nice words!
I think _null_ has a point. On my box, polingjw2 seems to run faster than polingjw1 below.
/* test data */
data test;
array var{20};
do i = 1 to 1000000;
do j=1 to dim(var);
var{j} = floor(ranuni(0)*300);
end;
output;
end;
drop i j;
run;
sasfile work.test.data open;
/* dummy step to load the data into sasfile.
see Mark^s sas-l posting
http://www.listserv.uga.edu/cgi-bin/wa?A2=ind1102B&L=sas-l&D=1&H=0&O=D&T=1&P=10531 */
data _null_;
set test;
run;
%macro ne(array, elements);
%do i = 1 %to %eval(&elements-2);
%do j = %eval(&i+1) %to &elements;
(&array[&i] ne &array[&j]) &
%end;
%end;
(&array[%eval(&elements-1)] ne &array[&elements])
%mend;
data polingjw1;
set test;
array var var:;
unique = (%ne(var, 20));
run;
%macro allDiff(root=, dim=);
%local i j maxi minj;
%let maxi = %eval(&dim - 2);
%do i = 1 %to &maxi;
%let minj = %eval(&i + 1);
%do j = &minj %to &dim;
%*; &root.&i ne &root&j &
%end;
%end;
&root.%eval(&dim - 1) ne &root.&dim
%mend allDiff;
/* using no arrays but the variable names directly. it also
takes advantage of if expression short-circuiting as well.
see this and the thread mentioned in it:
http://www.listserv.uga.edu/cgi-bin/wa?A2=ind0406D&L=sas-l&D=1&H=0&O=D&T=1&P=45708 */
data polingjw2;
set test;
if %allDiff(root=var, dim=20) then unique = 1;
else unique = 0;
run;
sasfile work.test.data close;
... View more