closest value into a macro variable

Hi everyone,

I have a numeric variable, lets call it 'times'. I have a macro variable 'myTime' defined to be some value, lets say 200. I would like to extract the closest value in 'times' to 'myTime' as a new macro variable 'closestTime'.

Would anyone know how to modify the code below so it gives the closest time instead of the smallest difference? (Or know of some other way I could extract the closest time into a macro variable?). Help is much appreciated!

proc sql noprint;
select min(abs(times-&myTime) )
into :closestTime
from myData;

thank you!
One simple way would be to do it in a data step if your data in not huge
Something like this should work..
data _null_;
set myData(end=last);
retain mindiff 0;
if last call symput("closestTime",mindiff);
PS: Code not tested