<?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: Find the second lowest value over the past of 36 months in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Find-the-second-lowest-value-over-the-past-of-36-months/m-p/889564#M44092</link>
    <description>&lt;P&gt;This is really simple, SAS has already done the hard work for you and created &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/proc/p0le3p5ngj1zlbn1mh3tistq9t76.htm" target="_self"&gt;PROC RANK&lt;/A&gt;, which will find the second lowest value&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc rank data=have out=ranks;&lt;BR /&gt;by permno;
var price;
ranks price_ranks;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then find the value in data set RANKS where variable price_ranks=2. This will handle ties in any one of a number of ways that you can select.&lt;/P&gt;</description>
    <pubDate>Wed, 16 Aug 2023 22:04:49 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-08-16T22:04:49Z</dc:date>
    <item>
      <title>Find the second lowest value over the past of 36 months</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Find-the-second-lowest-value-over-the-past-of-36-months/m-p/889551#M44087</link>
      <description>&lt;P&gt;I have around 1000 firms' monthly stock prices, and I need to find each firm's second lowest value over the past 36 months. The data looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PERMNO&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DATE&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PRICE&lt;/P&gt;&lt;P&gt;10001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2011-1-31&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9.875&lt;/P&gt;&lt;P&gt;10001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2011-2-28&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9.7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;10001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2022-12-31&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10.2&lt;/P&gt;&lt;P&gt;10002&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2011-1-31&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20.61&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;10002&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2022-12-31&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;15.65&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Starting from&amp;nbsp;&amp;nbsp;2011-1-31, the second lowest stock price in the 36 months would be 2014's value.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2023 20:04:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Find-the-second-lowest-value-over-the-past-of-36-months/m-p/889551#M44087</guid>
      <dc:creator>sfan6</dc:creator>
      <dc:date>2023-08-16T20:04:51Z</dc:date>
    </item>
    <item>
      <title>Re: Find the second lowest value over the past of 36 months</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Find-the-second-lowest-value-over-the-past-of-36-months/m-p/889552#M44088</link>
      <description>&lt;P&gt;How do you want to treat ties?&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2023 20:12:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Find-the-second-lowest-value-over-the-past-of-36-months/m-p/889552#M44088</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-16T20:12:42Z</dc:date>
    </item>
    <item>
      <title>Re: Find the second lowest value over the past of 36 months</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Find-the-second-lowest-value-over-the-past-of-36-months/m-p/889555#M44089</link>
      <description>Use the common way. Assign the average rank of the tied values&lt;BR /&gt;</description>
      <pubDate>Wed, 16 Aug 2023 20:17:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Find-the-second-lowest-value-over-the-past-of-36-months/m-p/889555#M44089</guid>
      <dc:creator>sfan6</dc:creator>
      <dc:date>2023-08-16T20:17:41Z</dc:date>
    </item>
    <item>
      <title>Re: Find the second lowest value over the past of 36 months</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Find-the-second-lowest-value-over-the-past-of-36-months/m-p/889556#M44090</link>
      <description>&lt;P&gt;What exactly does the desired output look like? A report or a data set? Is Permno the variable with the "firm" information? If not how do we know which records go with which firm?&lt;/P&gt;
&lt;P&gt;If there is a tie for "second lowest price" do you have a rule for secondary selection criteria.&lt;/P&gt;
&lt;P&gt;What if there is no "second lowest price" such as would occur with only one price value?&lt;/P&gt;
&lt;P&gt;Do any records have missing values for price? Missing is "lowest" generally so would perhaps affect your meaning for "second lowest" if you don't want to include those.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A relative generic approach ignoring any secondary rules assuming you want a data set.&lt;/P&gt;
&lt;PRE&gt;proc sort data=have;
   by permno price;
run;

data want;
   set have;
   by permno;
   retain counter;
   if first.permno then counter=1;
   else counter+1;
   if counter=2 then output;
   drop counter;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2023 20:23:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Find-the-second-lowest-value-over-the-past-of-36-months/m-p/889556#M44090</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-08-16T20:23:49Z</dc:date>
    </item>
    <item>
      <title>Re: Find the second lowest value over the past of 36 months</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Find-the-second-lowest-value-over-the-past-of-36-months/m-p/889564#M44092</link>
      <description>&lt;P&gt;This is really simple, SAS has already done the hard work for you and created &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/proc/p0le3p5ngj1zlbn1mh3tistq9t76.htm" target="_self"&gt;PROC RANK&lt;/A&gt;, which will find the second lowest value&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc rank data=have out=ranks;&lt;BR /&gt;by permno;
var price;
ranks price_ranks;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then find the value in data set RANKS where variable price_ranks=2. This will handle ties in any one of a number of ways that you can select.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2023 22:04:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Find-the-second-lowest-value-over-the-past-of-36-months/m-p/889564#M44092</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-08-16T22:04:49Z</dc:date>
    </item>
    <item>
      <title>Re: Find the second lowest value over the past of 36 months</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Find-the-second-lowest-value-over-the-past-of-36-months/m-p/889644#M44096</link>
      <description>&lt;P&gt;The EXTREMEOBS table in PROC UNIVARIATE is also helpful in identifying observations in the tails of your data. Use the ODS OUTPUT statement to write those observations to a SAS data set.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2023 13:14:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Find-the-second-lowest-value-over-the-past-of-36-months/m-p/889644#M44096</guid>
      <dc:creator>StatsMan</dc:creator>
      <dc:date>2023-08-17T13:14:30Z</dc:date>
    </item>
  </channel>
</rss>

