/* modified polingjw^s test data */
data test;
array var{32} var01-var32;
do x=1 to 1e6;
do i=-15 to 16;
var{i+16} = i*ranuni(0);
end;
output;
end;
drop i x;
run;
/* polingjw */
proc transpose data=test out=test_transpose name=var;
run;
data polingjw;
set test_transpose;
array col{*} col:;
array max_{5};
array min_{5};
do i=1 to 5;
max_{i} = max(of col
min_{i} = min(of col
do j=1 to dim(col);
if col{j}=min_{i} then col{j}= .;
if col{j}=max_{i} then col{j}=.;
end;
end;
keep var max_: min_:;
run;
/* re-shape to long for comparisons */
data polingjwLong;
set polingjw;
length var $32 type $6 num value 8;
keep var type num value;
array max_(5) max_1 - max_5;
array min_(5) min_1 - min_5;
do num = 1 to 5;
type = "top";
value = max_(num);
output;
end;
do num = 1 to 5;
type = "bottom";
value = min_(num);
output;
end;
run;
/* chang */
%let maxNumVars = 3000;
%let top = 5;
data chang;
set test end=end;
array top(1:&maxNumVars,-&top:&top) _temporary_;
array cur(*) _numeric_;
do k = 1 to dim(cur);
if missing(cur(k)) then leave;
link doTop;
link doBottom;
end;
if end then link doOutput;
return;
doTop:
do j = 1 to ⊤
if missing(top(k,j)) then do;
top(k,j) = cur(k);
leave;
end;
if (cur(k) < top(k,j)) then continue;
if (cur(k) = top(k,j)) then leave;
do i = &top to j+1 by -1;
top(k, i) = top(k, i-1);
end;
top(k, j) = cur(k);
leave;
end;
return;
doBottom:
do j = 1 to ⊤
if missing(top(k,-j)) then do;
top(k,-j) = cur(k);
leave;
end;
if (cur(k) > top(k,-j)) then continue;
if (cur(k) = top(k,-j)) then leave;
do i = &top to j+1 by -1;
top(k,-i) = top(k,-i+1);
end;
top(k,-j) = cur(k);
leave;
end;
return;
doOutput:
length var $32 type $6;
do k = 1 to dim(cur);
var = vname(cur(k));
type = "top";
do num = 1 to ⊤
value = top(k, num);
output;
end;
type = "bottom";
do num = 1 to ⊤
value = top(k,-num);
output;
end;
end;
keep var type num value;
return;
run;
proc compare base=polingjwLong comp=chang;
run;
/* on log, in part
NOTE: No unequal values were found. All values compared are exactly equal.
*/
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.