proc fcmp outlib = work.funcs.Math;
function MinDis(Exp,Arr[*]);
array dis[2] /nosymbols;
call dynamic_array(dis,dim(Arr));
do i = 1 to dim(Arr);
dis[i] = abs((Exp - Arr[i]));
end;
return(min(of dis[*]));
endsub;
quit;
option cmplib=work.funcs ;
data MinDis;
input LamdazLower LamdazUpper @;
cards;
2.50 10.0
2.51 10.8
2.49 9.97
2.75 9.50
;
run;
data _null_;
set ;
array _PTN_ [14] _temporary_ (0.5,1,1.5,2,2.5,3,4,5,6,7,8,9,10,12);
StdLamZLow = MinDis(LamdazLower,_PTN_);
StdLamZUpp = MinDis(LamdazUpper,_PTN_);
put _all_;
run;
It was compile rightly but gave wrong results. StdLamZLow
just get the minimum distance from LamdazLower
to the first two element of array _PTN_
.
When I rewrite the dim of dis
as 999 or something very big and get rid of call dynamic_array
statement I would get it right. But I surely want to know why min(of dis[*])
just take dis
as a 2-dim array.
By the way, how can I use implied DO-loops do over ...
to instead of explicit DO loops? I have tried several times but haven`t success yet.
Thanks for any hints.