<?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 Choosing observation based on condition of being closest to target number in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Choosing-observation-based-on-condition-of-being-closest-to/m-p/358316#M84170</link>
    <description>&lt;P&gt;Here is some sample data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
  format Target_Cost Total_Factor_Cost dollar10.2 Factor 4.2; 
  input Target_Cost Total_Factor_Cost Factor;
  datalines;
459 487.22 0.81
459 493.23 0.82
459 481.20 0.80
459 499.25 0.83
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And here is what I want for the output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Want;
  format Target_Cost Total_Factor_Cost dollar10.2 Factor 4.2; 
  input Target_Cost Total_Factor_Cost Factor;
  datalines;
459 481.20 0.80
;;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What I'm trying to accomplish is: return only the observation where the Total_Factor_Cost is closest to the Target_Cost (out of all the Total_Factor_Costs, which one is closest to the Target_Cost?), whether that be greater than, less than, or equal to the Target_Cost.&lt;/P&gt;</description>
    <pubDate>Fri, 12 May 2017 18:53:10 GMT</pubDate>
    <dc:creator>JediApprentice</dc:creator>
    <dc:date>2017-05-12T18:53:10Z</dc:date>
    <item>
      <title>Choosing observation based on condition of being closest to target number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Choosing-observation-based-on-condition-of-being-closest-to/m-p/358316#M84170</link>
      <description>&lt;P&gt;Here is some sample data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
  format Target_Cost Total_Factor_Cost dollar10.2 Factor 4.2; 
  input Target_Cost Total_Factor_Cost Factor;
  datalines;
459 487.22 0.81
459 493.23 0.82
459 481.20 0.80
459 499.25 0.83
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And here is what I want for the output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Want;
  format Target_Cost Total_Factor_Cost dollar10.2 Factor 4.2; 
  input Target_Cost Total_Factor_Cost Factor;
  datalines;
459 481.20 0.80
;;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What I'm trying to accomplish is: return only the observation where the Total_Factor_Cost is closest to the Target_Cost (out of all the Total_Factor_Costs, which one is closest to the Target_Cost?), whether that be greater than, less than, or equal to the Target_Cost.&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 18:53:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Choosing-observation-based-on-condition-of-being-closest-to/m-p/358316#M84170</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2017-05-12T18:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: Choosing observation based on condition of being closest to target number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Choosing-observation-based-on-condition-of-being-closest-to/m-p/358334#M84171</link>
      <description>&lt;P&gt;Good task for proc sql:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data Have;
  format Target_Cost Total_Factor_Cost dollar10.2 Factor 4.2; 
  input Target_Cost Total_Factor_Cost Factor;
  datalines;
459 487.22 0.81
459 493.23 0.82
459 481.20 0.80
459 499.25 0.83
;
run;

proc sql;
  create table want as
    select *
      from have
        having abs(Target_Cost-Total_Factor_Cost) eq min(abs(Target_Cost-Total_Factor_Cost))
  ;
quit;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 19:41:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Choosing-observation-based-on-condition-of-being-closest-to/m-p/358334#M84171</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-05-12T19:41:24Z</dc:date>
    </item>
    <item>
      <title>Re: Choosing observation based on condition of being closest to target number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Choosing-observation-based-on-condition-of-being-closest-to/m-p/358336#M84173</link>
      <description>&lt;P&gt;something like this should work&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Target_Cost, Total_Factor_Cost, Factor &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;from&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Target_Cost, Total_Factor_Cost , Factor, abs(Target_Cost-Total_Factor_Cost) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; dif&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; have&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;having&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; dif =min(dif));&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 19:43:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Choosing-observation-based-on-condition-of-being-closest-to/m-p/358336#M84173</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2017-05-12T19:43:12Z</dc:date>
    </item>
  </channel>
</rss>

