<?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: Finding maximum value in a column within a subset/group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Finding-maximum-value-in-a-column-within-a-subset-group/m-p/94421#M19899</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are right, this is not obvious, but that is the way I want them to be (it makes sense in the original dataset). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;max3_value=4 is OK, as it is a max(2,3,4). &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 08 Dec 2012 20:10:47 GMT</pubDate>
    <dc:creator>neq1337</dc:creator>
    <dc:date>2012-12-08T20:10:47Z</dc:date>
    <item>
      <title>Finding maximum value in a column within a subset/group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-maximum-value-in-a-column-within-a-subset-group/m-p/94418#M19896</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a data similar to the one below, but without the max3_value column. This is the one I would like to find, but I do not know how.&lt;/P&gt;&lt;P&gt;max3_value takes the last 3 values of the value column (within a group of person) and finds the maximum value of them. Of course, if it is the first or the second observation, it outputs a missing value.&lt;/P&gt;&lt;P&gt;For example: max3_value=10 in period 3 for person A is calculated as a max(10,5,3).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I thought of transposing the data with lagged values, but still I do not know how calculate it within groups of person.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would kindly appreciate any help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 285px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl64" height="20" width="64"&gt;person&lt;/TD&gt;&lt;TD class="xl64" style="border-left: none;" width="64"&gt;period&lt;/TD&gt;&lt;TD class="xl64" style="border-left: none;" width="64"&gt;value&lt;/TD&gt;&lt;TD class="xl64" style="border-left: none;" width="93"&gt;max3_value&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" style="border-top: none;"&gt;A&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;10&lt;/TD&gt;&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" style="border-top: none;"&gt;A&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;5&lt;/TD&gt;&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" style="border-top: none;"&gt;A&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;3&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;3&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" style="border-top: none;"&gt;A&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;4&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;5&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" style="border-top: none;"&gt;A&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;5&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" style="border-top: none;"&gt;A&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;6&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;3&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" style="border-top: none;"&gt;A&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;7&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;4&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" style="border-top: none;"&gt;A&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;8&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;14&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;14&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" style="border-top: none;"&gt;B&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;6&lt;/TD&gt;&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" style="border-top: none;"&gt;B&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;5&lt;/TD&gt;&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" style="border-top: none;"&gt;B&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;3&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" style="border-top: none;"&gt;B&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;4&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" style="border-top: none;"&gt;B&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;5&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;4&lt;/TD&gt;&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Dec 2012 19:01:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-maximum-value-in-a-column-within-a-subset-group/m-p/94418#M19896</guid>
      <dc:creator>neq1337</dc:creator>
      <dc:date>2012-12-08T19:01:28Z</dc:date>
    </item>
    <item>
      <title>Re: Finding maximum value in a column within a subset/group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-maximum-value-in-a-column-within-a-subset-group/m-p/94419#M19897</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;One way is populate variables with the previous 2 values and keep count of how many obs you have seen for this person.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by person ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; lag1=lag1(value);&lt;/P&gt;&lt;P&gt;&amp;nbsp; lag2=lag2(value);&lt;/P&gt;&lt;P&gt;&amp;nbsp; if first.person then cnt=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cnt + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if cnt &amp;lt; 3 then max3=.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else max3 = max(lag1,lag2,value);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Dec 2012 19:54:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-maximum-value-in-a-column-within-a-subset-group/m-p/94419#M19897</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-12-08T19:54:12Z</dc:date>
    </item>
    <item>
      <title>Re: Finding maximum value in a column within a subset/group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-maximum-value-in-a-column-within-a-subset-group/m-p/94420#M19898</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why is it obvious that the first two values will be missing?&amp;nbsp; Do you always want them to be?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, why is the next to the last value for person A assigned the value 4?&amp;nbsp; Was that supposed to be 14?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Dec 2012 19:59:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-maximum-value-in-a-column-within-a-subset-group/m-p/94420#M19898</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-12-08T19:59:36Z</dc:date>
    </item>
    <item>
      <title>Re: Finding maximum value in a column within a subset/group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-maximum-value-in-a-column-within-a-subset-group/m-p/94421#M19899</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are right, this is not obvious, but that is the way I want them to be (it makes sense in the original dataset). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;max3_value=4 is OK, as it is a max(2,3,4). &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Dec 2012 20:10:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-maximum-value-in-a-column-within-a-subset-group/m-p/94421#M19899</guid>
      <dc:creator>neq1337</dc:creator>
      <dc:date>2012-12-08T20:10:47Z</dc:date>
    </item>
    <item>
      <title>Re: Finding maximum value in a column within a subset/group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-maximum-value-in-a-column-within-a-subset-group/m-p/94422#M19900</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tom's suggested code appears to accomplish what you want.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Dec 2012 20:27:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-maximum-value-in-a-column-within-a-subset-group/m-p/94422#M19900</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-12-08T20:27:38Z</dc:date>
    </item>
    <item>
      <title>Re: Finding maximum value in a column within a subset/group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-maximum-value-in-a-column-within-a-subset-group/m-p/94423#M19901</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually it should be 5 as the max of 5,1,1 is 5.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Dec 2012 20:28:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-maximum-value-in-a-column-within-a-subset-group/m-p/94423#M19901</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-12-08T20:28:21Z</dc:date>
    </item>
    <item>
      <title>Re: Finding maximum value in a column within a subset/group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-maximum-value-in-a-column-within-a-subset-group/m-p/94424#M19902</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for prompt response, it works perfectly. &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Dec 2012 20:32:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-maximum-value-in-a-column-within-a-subset-group/m-p/94424#M19902</guid>
      <dc:creator>neq1337</dc:creator>
      <dc:date>2012-12-08T20:32:28Z</dc:date>
    </item>
    <item>
      <title>Re: Finding maximum value in a column within a subset/group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-maximum-value-in-a-column-within-a-subset-group/m-p/94425#M19903</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A __default_attr="2431" __jive_macro_name="user" class="jive_macro jive_macro_user" data-objecttype="3" href="https://communities.sas.com/"&gt;&lt;/A&gt;: You are correct about the line you referenced, but I was asking about an earlier line.&amp;nbsp; I had seen the last three assignments and figured that the OP was simply looking at groups of three.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regardless, your code apparently does precisely what the OP was looking for.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Dec 2012 23:28:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-maximum-value-in-a-column-within-a-subset-group/m-p/94425#M19903</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-12-08T23:28:31Z</dc:date>
    </item>
  </channel>
</rss>

