<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic look around in SAS Data Science</title>
    <link>https://communities.sas.com/t5/SAS-Data-Science/look-around/m-p/336290#M5030</link>
    <description>&lt;P&gt;How &amp;nbsp;to pick up the nearest number of 26.33 from data set(25,25.5,26,26.5,27).&lt;/P&gt;</description>
    <pubDate>Mon, 27 Feb 2017 18:14:33 GMT</pubDate>
    <dc:creator>Xinhui</dc:creator>
    <dc:date>2017-02-27T18:14:33Z</dc:date>
    <item>
      <title>look around</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/look-around/m-p/336290#M5030</link>
      <description>&lt;P&gt;How &amp;nbsp;to pick up the nearest number of 26.33 from data set(25,25.5,26,26.5,27).&lt;/P&gt;</description>
      <pubDate>Mon, 27 Feb 2017 18:14:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/look-around/m-p/336290#M5030</guid>
      <dc:creator>Xinhui</dc:creator>
      <dc:date>2017-02-27T18:14:33Z</dc:date>
    </item>
    <item>
      <title>Re: look around</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/look-around/m-p/336323#M5033</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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&amp;lt;-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) &amp;lt; big then do; big=abs(dif); sav=nums[1,i]; end;

FULL SOLUTIONS
==============

*____
|  _ \
| |_) |
|  _ &amp;lt;
|_| \_\
;

%utl_submit_r64('
  nums&amp;lt;-c(25,25.5,26,26.5,27);
  nums[which.min(abs(nums - 26.33))];
');

&amp;gt; nums&amp;lt;-c(25,25.5,26,26.5,27);  nums[which.min(abs(nums - 26.33))];
[1] 26.5
&amp;gt;


*____    _    ____     __        ______  ____
/ ___|  / \  / ___|    \ \      / /  _ \/ ___|
\___ \ / _ \ \___ \ ____\ \ /\ / /| |_) \___ \
 ___) / ___ \ ___) |_____\ 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) &amp;lt; 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) &amp;lt; 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;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Feb 2017 19:52:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/look-around/m-p/336323#M5033</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-02-27T19:52:57Z</dc:date>
    </item>
    <item>
      <title>Re: look around</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/look-around/m-p/337225#M5040</link>
      <description>&lt;P&gt;First of all, thank you for your help. The code you gave me works well. There is another problem, however. In my case, we have three variables - the underlying price, the strike price, and the datadate. When the program&amp;nbsp;picks up the strike price that is nearest to the underlying price, I also need it&amp;nbsp;to consider the datadate. Please see the attached document for a sample.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So basically, I need it to pick the nearest strike price within that given date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, on 2011/1/16, the underlying price is 26.33. The closest strike price is 26.5.&amp;nbsp;&lt;/P&gt;&lt;P&gt;On 2011/1/17, the underlying price is 26.11 and the closest strike price is 26.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 03:40:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/look-around/m-p/337225#M5040</guid>
      <dc:creator>Xinhui</dc:creator>
      <dc:date>2017-03-02T03:40:35Z</dc:date>
    </item>
  </channel>
</rss>

