<?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: Selecting rows with absolute minimum within each group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Selecting-rows-with-absolute-minimum-within-each-group/m-p/451334#M113755</link>
    <description>&lt;P&gt;Could this solution be modified in a way that all other columns in the dataset are also included?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 04 Apr 2018 22:19:46 GMT</pubDate>
    <dc:creator>corkee</dc:creator>
    <dc:date>2018-04-04T22:19:46Z</dc:date>
    <item>
      <title>Selecting rows with absolute minimum within each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-rows-with-absolute-minimum-within-each-group/m-p/451324#M113749</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset that's structured like the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;participant_id     v1datediff
1                         -22
1                         10
1                         -2
2                         1
2                         3
3                         2&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to only extract rows where the absolute value of v1datediff is the minimum for each individual (i.e., I want rows 3, 4, and 6). I've merged two datasets together and have attempted the following code, but to no avail. Any suggestions would be appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table visit1_merged as
	select *,
	v1completedate-date as v1datediff
		from
			visit1_want
			full join
			ehr_data
			on visit1_want.chldmrn=ehr_data.chldmrn
	;
quit;


proc sql;
	create table v1final as
	select *
	from visit1_merged
	group by participant_id
	having v1datediff = abs(min(v1datediff))
	;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 22:15:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-rows-with-absolute-minimum-within-each-group/m-p/451324#M113749</guid>
      <dc:creator>corkee</dc:creator>
      <dc:date>2018-04-04T22:15:46Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting rows with absolute minimum within each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-rows-with-absolute-minimum-within-each-group/m-p/451327#M113750</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/122635"&gt;@corkee&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset that's structured like the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;participant_id     v1datediff
1                         -22
1                         10
1                         -2
2                         1
2                         3
3                         2&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want to only extract rows where the absolute value of v1datediff is the minimum for each individual (i.e., I want rows 3, 5, and 6).&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Should that say "Rows 3, 4 and 6"????&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC SUMMARY will tell you the minimum value of v1datediff, provided you take the absolute value in data step prior to PROC SUMMARY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So assuming you have so type of ID in the data set (which could simply be rownumber), this ought to work&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    set have;
    absv1datediff=abs(v1datediff);
    rownumber = _n_;
run;
proc summary data=have nway idmin;
    class participant_id;
    var absv1datediff;
    id rownumber;
    output out=minimums min=min_v1datediff;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Apr 2018 22:09:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-rows-with-absolute-minimum-within-each-group/m-p/451327#M113750</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-04-04T22:09:25Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting rows with absolute minimum within each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-rows-with-absolute-minimum-within-each-group/m-p/451330#M113752</link>
      <description>Hi, yes. I'll go edit that.&lt;BR /&gt;&lt;BR /&gt;Let me try your proposed solution and let you know. Thank you.</description>
      <pubDate>Wed, 04 Apr 2018 22:15:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-rows-with-absolute-minimum-within-each-group/m-p/451330#M113752</guid>
      <dc:creator>corkee</dc:creator>
      <dc:date>2018-04-04T22:15:10Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting rows with absolute minimum within each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-rows-with-absolute-minimum-within-each-group/m-p/451334#M113755</link>
      <description>&lt;P&gt;Could this solution be modified in a way that all other columns in the dataset are also included?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 22:19:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-rows-with-absolute-minimum-within-each-group/m-p/451334#M113755</guid>
      <dc:creator>corkee</dc:creator>
      <dc:date>2018-04-04T22:19:46Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting rows with absolute minimum within each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-rows-with-absolute-minimum-within-each-group/m-p/451347#M113760</link>
      <description>&lt;P&gt;Included in what way? Explain. Give examples.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 23:08:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-rows-with-absolute-minimum-within-each-group/m-p/451347#M113760</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-04-04T23:08:55Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting rows with absolute minimum within each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-rows-with-absolute-minimum-within-each-group/m-p/451390#M113784</link>
      <description>&lt;P&gt;I can't test this right now, but I expect that your original code is very close.&amp;nbsp; A slight modification to the HAVING clause:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;having abs(v1datediff) = min(abs(v1datediff));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might get multiple rows for an individual, if there are ties for the minimum value.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Apr 2018 03:43:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-rows-with-absolute-minimum-within-each-group/m-p/451390#M113784</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-04-05T03:43:45Z</dc:date>
    </item>
  </channel>
</rss>

