How to pick up the nearest number of 26.33 from data set(25,25.5,26,26.5,27).
If you have the IML interface to R you should
be able to just cut and paste into the interface.
inspired by
https://goo.gl/Wc5cGb
https://communities.sas.com/t5/SAS-Data-Mining/look-around/m-p/336290
HAVE
25, 25.5, 26, 26.5, 27
and
26,33
WANT
26.5
FULL SOLUTION
=============
R nums<-c(25,25.5,26,26.5,27);
nums[which.min(abs(nums - 26.33))];
Sas array nums[2,5] _temporary_ (25,25.5,26,26.5,27 5*26.33);
dif=nums[1,i]-nums[2,i];
if abs(dif) < big then do; big=abs(dif); sav=nums[1,i]; end;
FULL SOLUTIONS
==============
*____
| _ \
| |_) |
| _ <
|_| \_\
;
%utl_submit_r64('
nums<-c(25,25.5,26,26.5,27);
nums[which.min(abs(nums - 26.33))];
');
> nums<-c(25,25.5,26,26.5,27); nums[which.min(abs(nums - 26.33))];
[1] 26.5
>
*____ _ ____ __ ______ ____
/ ___| / \ / ___| \ \ / / _ \/ ___|
\___ \ / _ \ \___ \ ____\ \ /\ / /| |_) \___ \
___) / ___ \ ___) |_____\ V V / | __/ ___) |
|____/_/ \_\____/ \_/\_/ |_| |____/
;
data _null_;
array nums[2,5] _temporary_ (25,25.5,26,26.5,27 5*26.33);
big=constant('big');
do i=1 to 5;
dif=nums[1,i]-nums[2,i];
if abs(dif) < big then do; big=abs(dif); sav=nums[1,i]; end;
end;
put nums[2,1] sav big;
run;quit;
759 data _null_;
760 array nums[2,5] _temporary_ (25,25.5,26,26.5,27 5*26.33);
761 big=constant('big');
762 do i=1 to 5;
763 dif=nums[1,i]-nums[2,i];
764 if abs(dif) < big then do; big=abs(dif); sav=nums[1,i]; end;
765 end;
766 put nums[2,1] sav big;
767 run;
26.33 26.5 0.17
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
user cpu time 0.01 seconds
system cpu time 0.00 seconds
memory 261.43k
OS Memory 13540.00k
Timestamp 02/27/2017 11:51:09 AM
Step Count 153 Switch Count 0
767 ! quit;
... View more