<?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 Re: SAS function to get closet value to x in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-function-to-get-closet-value-to-x/m-p/66205#M14374</link>
    <description>Does this do what you want?&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
   select *&lt;BR /&gt;
   from new &lt;BR /&gt;
   where abs(50-b) =(select min(abs(50-b)) from new);&lt;BR /&gt;
quit;</description>
    <pubDate>Fri, 21 Aug 2009 21:38:29 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2009-08-21T21:38:29Z</dc:date>
    <item>
      <title>SAS function to get closet value to x</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-function-to-get-closet-value-to-x/m-p/66203#M14372</link>
      <description>Hi SAS users,&lt;BR /&gt;
&lt;BR /&gt;
Is there any SAS function identifying the closest value to 50 in the variable B &lt;BR /&gt;
in the a dataset below. If not, any other way to get the value without using SAS function.&lt;BR /&gt;
&lt;BR /&gt;
Thank you&lt;BR /&gt;
FP&lt;BR /&gt;
&lt;BR /&gt;
data new;&lt;BR /&gt;
input A B;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 50.10&lt;BR /&gt;
1 50.2&lt;BR /&gt;
2 49.99&lt;BR /&gt;
2 49.7&lt;BR /&gt;
3 49.8&lt;BR /&gt;
3 49.90&lt;BR /&gt;
4 50.7&lt;BR /&gt;
4 50.3&lt;BR /&gt;
5 50.5&lt;BR /&gt;
5 50.6&lt;BR /&gt;
;&lt;BR /&gt;
run;</description>
      <pubDate>Fri, 21 Aug 2009 19:35:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-function-to-get-closet-value-to-x/m-p/66203#M14372</guid>
      <dc:creator>fp</dc:creator>
      <dc:date>2009-08-21T19:35:09Z</dc:date>
    </item>
    <item>
      <title>Re: SAS function to get closet value to x</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-function-to-get-closet-value-to-x/m-p/66204#M14373</link>
      <description>If you use ABS(B-50) as a distance then find MIN would that be adequate?&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data new;&lt;BR /&gt;
   input A B;&lt;BR /&gt;
   dif = abs(b-50);&lt;BR /&gt;
   datalines;&lt;BR /&gt;
1 50.10&lt;BR /&gt;
1 50.2&lt;BR /&gt;
2 49.99&lt;BR /&gt;
2 49.7&lt;BR /&gt;
3 49.8&lt;BR /&gt;
3 49.90&lt;BR /&gt;
4 50.7&lt;BR /&gt;
4 50.3&lt;BR /&gt;
5 50.5&lt;BR /&gt;
5 50.6&lt;BR /&gt;
;&lt;BR /&gt;
   run; &lt;BR /&gt;
proc summary nway;&lt;BR /&gt;
   class a;&lt;BR /&gt;
   output out=work.closest(drop=_:) idgroup(min(dif) out(b)=);&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Fri, 21 Aug 2009 21:34:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-function-to-get-closet-value-to-x/m-p/66204#M14373</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-08-21T21:34:06Z</dc:date>
    </item>
    <item>
      <title>Re: SAS function to get closet value to x</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-function-to-get-closet-value-to-x/m-p/66205#M14374</link>
      <description>Does this do what you want?&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
   select *&lt;BR /&gt;
   from new &lt;BR /&gt;
   where abs(50-b) =(select min(abs(50-b)) from new);&lt;BR /&gt;
quit;</description>
      <pubDate>Fri, 21 Aug 2009 21:38:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-function-to-get-closet-value-to-x/m-p/66205#M14374</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2009-08-21T21:38:29Z</dc:date>
    </item>
  </channel>
</rss>

