<?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 Finding the second minimum if observation with first minimum does not satisfy other conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-second-minimum-if-observation-with-first-minimum/m-p/451529#M113851</link>
    <description>&lt;P&gt;Hi, I am trying to extract only observations with the smallest absolute value for v1datediff. There are multiple rows of data for each unique individual, so not only do I want to extract the minimum v1datediff, but I also want to make sure that if the minimum v1datediff has missing values for another column, then I would take the next minimum with complete data. Is this doable in PROC SQL or base SAS?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;participant_id     length     absv1datediff
1                         2            1
1                         2.2          9
1                         .            2
1                         2.1          3
2                         .            0
2                         1.9          1
2                         1.9          5&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So for the above dataset, I'd like to extract, for participant 1, the first row (where length is 2). For participant 2, the minimum absv1datediff is 0 (row 5), but since it has missing length, I'd like to extract the NEXT minimum, which is row 6.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried something like the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table v1final as
	select *, abs(v1datediff) as absv1datediff, abs(ehr_height_cm - inflengthcm_v1) as measurement_diff
	from visit1_merged
	group by participant_id
	having absv1datediff = min(absv1datediff) and length ne .
	;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 05 Apr 2018 14:42:13 GMT</pubDate>
    <dc:creator>corkee</dc:creator>
    <dc:date>2018-04-05T14:42:13Z</dc:date>
    <item>
      <title>Finding the second minimum if observation with first minimum does not satisfy other conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-second-minimum-if-observation-with-first-minimum/m-p/451529#M113851</link>
      <description>&lt;P&gt;Hi, I am trying to extract only observations with the smallest absolute value for v1datediff. There are multiple rows of data for each unique individual, so not only do I want to extract the minimum v1datediff, but I also want to make sure that if the minimum v1datediff has missing values for another column, then I would take the next minimum with complete data. Is this doable in PROC SQL or base SAS?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;participant_id     length     absv1datediff
1                         2            1
1                         2.2          9
1                         .            2
1                         2.1          3
2                         .            0
2                         1.9          1
2                         1.9          5&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So for the above dataset, I'd like to extract, for participant 1, the first row (where length is 2). For participant 2, the minimum absv1datediff is 0 (row 5), but since it has missing length, I'd like to extract the NEXT minimum, which is row 6.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried something like the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table v1final as
	select *, abs(v1datediff) as absv1datediff, abs(ehr_height_cm - inflengthcm_v1) as measurement_diff
	from visit1_merged
	group by participant_id
	having absv1datediff = min(absv1datediff) and length ne .
	;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Apr 2018 14:42:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-second-minimum-if-observation-with-first-minimum/m-p/451529#M113851</guid>
      <dc:creator>corkee</dc:creator>
      <dc:date>2018-04-05T14:42:13Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the second minimum if observation with first minimum does not satisfy other conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-second-minimum-if-observation-with-first-minimum/m-p/451562#M113875</link>
      <description>&lt;P&gt;For LENGTH, use WHERE instead of HAVING:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where length ne .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;instead of&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and length ne .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The rest can stay the same.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Apr 2018 15:18:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-second-minimum-if-observation-with-first-minimum/m-p/451562#M113875</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-04-05T15:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the second minimum if observation with first minimum does not satisfy other conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-the-second-minimum-if-observation-with-first-minimum/m-p/451585#M113884</link>
      <description>This is perfect. Thank you!</description>
      <pubDate>Thu, 05 Apr 2018 15:44:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-the-second-minimum-if-observation-with-first-minimum/m-p/451585#M113884</guid>
      <dc:creator>corkee</dc:creator>
      <dc:date>2018-04-05T15:44:10Z</dc:date>
    </item>
  </channel>
</rss>

