<?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: One row needs to be selected in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/One-row-needs-to-be-selected/m-p/68386#M14828</link>
    <description>&amp;gt; Something like this???&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; data one/view=one;&lt;BR /&gt;
&amp;gt;  set hello;&lt;BR /&gt;
&amp;gt; length diff 8;&lt;BR /&gt;
&amp;gt;  diff = var1 - var2;&lt;BR /&gt;
&amp;gt; un;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; proc sort data = one out = two;&lt;BR /&gt;
&amp;gt;  by id diff;&lt;BR /&gt;
&amp;gt; un;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; data three;&lt;BR /&gt;
&amp;gt;  set two;&lt;BR /&gt;
&amp;gt; by id diff;&lt;BR /&gt;
&amp;gt;  if first.id then output;&lt;BR /&gt;
&amp;gt; un;&lt;BR /&gt;
&lt;BR /&gt;
good approach and allowing ID groups.&lt;BR /&gt;
May need refinement to ensure dif is only positive. &lt;BR /&gt;
 &lt;BR /&gt;
The first refinement[pre]&amp;gt;  diff = abs( var1 - var2) ;[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
peterC</description>
    <pubDate>Mon, 30 Aug 2010 17:49:15 GMT</pubDate>
    <dc:creator>Peter_C</dc:creator>
    <dc:date>2010-08-30T17:49:15Z</dc:date>
    <item>
      <title>One row needs to be selected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-row-needs-to-be-selected/m-p/68383#M14825</link>
      <description>I have a dataset like this:&lt;BR /&gt;
&lt;BR /&gt;
data hello;&lt;BR /&gt;
input id var1 var2;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 3 5&lt;BR /&gt;
1 3 7&lt;BR /&gt;
2 2 4&lt;BR /&gt;
2 2 7&lt;BR /&gt;
2 2 9&lt;BR /&gt;
3 4 6&lt;BR /&gt;
3 4 9&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
I want to output only one row where the difference beetween var1 and var2 is lowest for the particular id. &lt;BR /&gt;
&lt;BR /&gt;
Any help.</description>
      <pubDate>Mon, 30 Aug 2010 14:00:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-row-needs-to-be-selected/m-p/68383#M14825</guid>
      <dc:creator>Sarojkumar</dc:creator>
      <dc:date>2010-08-30T14:00:01Z</dc:date>
    </item>
    <item>
      <title>Re: One row needs to be selected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-row-needs-to-be-selected/m-p/68384#M14826</link>
      <description>Consider PROC SQL with a sub-query (to get the minimum) or a DATA step using a MERGE / BY statement technique, while using a PROC SUMMARY to get the minimum value for your BY group.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Mon, 30 Aug 2010 14:28:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-row-needs-to-be-selected/m-p/68384#M14826</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-08-30T14:28:56Z</dc:date>
    </item>
    <item>
      <title>Re: One row needs to be selected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-row-needs-to-be-selected/m-p/68385#M14827</link>
      <description>Something like this???&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data one/view=one;&lt;BR /&gt;
 set hello;&lt;BR /&gt;
 length diff 8;&lt;BR /&gt;
 diff = var1 - var2;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data = one out = two;&lt;BR /&gt;
 by id diff;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data three;&lt;BR /&gt;
 set two;&lt;BR /&gt;
 by id diff;&lt;BR /&gt;
 if first.id then output;&lt;BR /&gt;
run;</description>
      <pubDate>Mon, 30 Aug 2010 15:23:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-row-needs-to-be-selected/m-p/68385#M14827</guid>
      <dc:creator>FredrikE</dc:creator>
      <dc:date>2010-08-30T15:23:52Z</dc:date>
    </item>
    <item>
      <title>Re: One row needs to be selected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-row-needs-to-be-selected/m-p/68386#M14828</link>
      <description>&amp;gt; Something like this???&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; data one/view=one;&lt;BR /&gt;
&amp;gt;  set hello;&lt;BR /&gt;
&amp;gt; length diff 8;&lt;BR /&gt;
&amp;gt;  diff = var1 - var2;&lt;BR /&gt;
&amp;gt; un;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; proc sort data = one out = two;&lt;BR /&gt;
&amp;gt;  by id diff;&lt;BR /&gt;
&amp;gt; un;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; data three;&lt;BR /&gt;
&amp;gt;  set two;&lt;BR /&gt;
&amp;gt; by id diff;&lt;BR /&gt;
&amp;gt;  if first.id then output;&lt;BR /&gt;
&amp;gt; un;&lt;BR /&gt;
&lt;BR /&gt;
good approach and allowing ID groups.&lt;BR /&gt;
May need refinement to ensure dif is only positive. &lt;BR /&gt;
 &lt;BR /&gt;
The first refinement[pre]&amp;gt;  diff = abs( var1 - var2) ;[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
peterC</description>
      <pubDate>Mon, 30 Aug 2010 17:49:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-row-needs-to-be-selected/m-p/68386#M14828</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-08-30T17:49:15Z</dc:date>
    </item>
  </channel>
</rss>

