<?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 select max from group of data in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/select-max-from-group-of-data/m-p/24092#M3673</link>
    <description>I have data that looks like this:&lt;BR /&gt;
&lt;BR /&gt;
Claim#      LossYr     RptYr         Amount&lt;BR /&gt;
 A	6	6	10000&lt;BR /&gt;
A	6	7	20000&lt;BR /&gt;
B	7	7	10000&lt;BR /&gt;
B	7	8	5000&lt;BR /&gt;
C	7	7	10000&lt;BR /&gt;
C	7	8	10000&lt;BR /&gt;
E	8	8	20000&lt;BR /&gt;
F	7	7	5000&lt;BR /&gt;
F	7	8	5000&lt;BR /&gt;
G	7	7	5000&lt;BR /&gt;
H	6	6	10000&lt;BR /&gt;
H	6	7	5000&lt;BR /&gt;
&lt;BR /&gt;
What I would like is to only see, for each claim #, the row relating to the highest report year (the value in the third column)&lt;BR /&gt;
&lt;BR /&gt;
So for A, I only want to see the 2nd row.  For G, there is only 1 row, and I want to see that row.  Any suggestions?</description>
    <pubDate>Tue, 01 Dec 2009 20:00:44 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-12-01T20:00:44Z</dc:date>
    <item>
      <title>select max from group of data</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/select-max-from-group-of-data/m-p/24092#M3673</link>
      <description>I have data that looks like this:&lt;BR /&gt;
&lt;BR /&gt;
Claim#      LossYr     RptYr         Amount&lt;BR /&gt;
 A	6	6	10000&lt;BR /&gt;
A	6	7	20000&lt;BR /&gt;
B	7	7	10000&lt;BR /&gt;
B	7	8	5000&lt;BR /&gt;
C	7	7	10000&lt;BR /&gt;
C	7	8	10000&lt;BR /&gt;
E	8	8	20000&lt;BR /&gt;
F	7	7	5000&lt;BR /&gt;
F	7	8	5000&lt;BR /&gt;
G	7	7	5000&lt;BR /&gt;
H	6	6	10000&lt;BR /&gt;
H	6	7	5000&lt;BR /&gt;
&lt;BR /&gt;
What I would like is to only see, for each claim #, the row relating to the highest report year (the value in the third column)&lt;BR /&gt;
&lt;BR /&gt;
So for A, I only want to see the 2nd row.  For G, there is only 1 row, and I want to see that row.  Any suggestions?</description>
      <pubDate>Tue, 01 Dec 2009 20:00:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/select-max-from-group-of-data/m-p/24092#M3673</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-12-01T20:00:44Z</dc:date>
    </item>
    <item>
      <title>Re: select max from group of data</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/select-max-from-group-of-data/m-p/24093#M3674</link>
      <description>What I tried to do was select all the data and select max for report year and group by everything else.  That did not work.</description>
      <pubDate>Tue, 01 Dec 2009 20:04:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/select-max-from-group-of-data/m-p/24093#M3674</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-12-01T20:04:49Z</dc:date>
    </item>
    <item>
      <title>Re: select max from group of data</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/select-max-from-group-of-data/m-p/24094#M3675</link>
      <description>I actually just thought of a way to do it, but I don't particularly like it.  I created an ID using the function "cats" using the first 3 variables.  The I created a new table which did not have the amount column and had the max from column 3 (report year).  Then I recreated the ID and joined back to the original dataset below.  It actually does exactly what I want, but I feel like there should be a more elegant way.  Any input would be greatly appreciated.&lt;BR /&gt;
&lt;BR /&gt;
I feel like I'm talking to myself here!</description>
      <pubDate>Tue, 01 Dec 2009 20:57:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/select-max-from-group-of-data/m-p/24094#M3675</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-12-01T20:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: select max from group of data</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/select-max-from-group-of-data/m-p/24095#M3676</link>
      <description>More talking to myself.&lt;BR /&gt;
&lt;BR /&gt;
I'm in the process of reading "The Little SAS Book" and I just stumbled across another way that I think I could do what I want.  It talks about an automatic variable called FIRST.variable and LAST.variable.  I feel like I could use LAST.Claim# and as long as I sort by claim number and report year, that would work.  However, I'm not sure if this functions exists in SAS EG or not and if so, how do I use it.</description>
      <pubDate>Tue, 01 Dec 2009 21:46:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/select-max-from-group-of-data/m-p/24095#M3676</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-12-01T21:46:44Z</dc:date>
    </item>
    <item>
      <title>Re: select max from group of data</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/select-max-from-group-of-data/m-p/24096#M3677</link>
      <description>There might be a fancy way to do it via the Rank task with a Group By variable.&lt;BR /&gt;
&lt;BR /&gt;
Use the Rank task to rank RptYr by Claim#.  Set the option to rank Largest to Smallest.  The result will have a rank_RptYr variable with values like 1,2, etc.&lt;BR /&gt;
&lt;BR /&gt;
Then use Query Builder to subset with just the rows where rank_RptYr = 1.&lt;BR /&gt;
&lt;BR /&gt;
Chris</description>
      <pubDate>Tue, 01 Dec 2009 21:48:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/select-max-from-group-of-data/m-p/24096#M3677</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2009-12-01T21:48:25Z</dc:date>
    </item>
    <item>
      <title>Re: select max from group of data</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/select-max-from-group-of-data/m-p/24097#M3678</link>
      <description>And yes, a simple DATA step can do the job as well.  Sort the data by claim and RptYr, then use the BY statement and FIRST. syntax to keep just the top years.&lt;BR /&gt;
&lt;BR /&gt;
Chris</description>
      <pubDate>Tue, 01 Dec 2009 21:49:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/select-max-from-group-of-data/m-p/24097#M3678</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2009-12-01T21:49:55Z</dc:date>
    </item>
    <item>
      <title>Re: select max from group of data</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/select-max-from-group-of-data/m-p/24098#M3679</link>
      <description>Here's the program *generated* by EG with my point and click approach (includes your sample data).&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data claims;&lt;BR /&gt;
length claim $ 1 LossYr 3 ReptYr 3 Amount 8;&lt;BR /&gt;
input claim LossYr ReptYr Amount;&lt;BR /&gt;
datalines;&lt;BR /&gt;
A 6 6 10000&lt;BR /&gt;
A 6 7 20000&lt;BR /&gt;
B 7 7 10000&lt;BR /&gt;
B 7 8 5000&lt;BR /&gt;
C 7 7 10000&lt;BR /&gt;
C 7 8 10000&lt;BR /&gt;
E 8 8 20000&lt;BR /&gt;
F 7 7 5000&lt;BR /&gt;
F 7 8 5000&lt;BR /&gt;
G 7 7 5000&lt;BR /&gt;
H 6 6 10000&lt;BR /&gt;
H 6 7 5000&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
/* generated by Rank Data task */&lt;BR /&gt;
PROC SORT&lt;BR /&gt;
	DATA=WORK.CLAIMS&lt;BR /&gt;
	OUT=WORK.SORTTempTableSorted&lt;BR /&gt;
	;&lt;BR /&gt;
	BY claim;&lt;BR /&gt;
RUN;&lt;BR /&gt;
PROC RANK DATA = WORK.SORTTempTableSorted&lt;BR /&gt;
	DESCENDING&lt;BR /&gt;
	TIES=MEAN&lt;BR /&gt;
	OUT=WORK.RANKEDCLAIMS;&lt;BR /&gt;
	BY claim;&lt;BR /&gt;
	VAR ReptYr;&lt;BR /&gt;
RANKS rank_ReptYr ;&lt;BR /&gt;
&lt;BR /&gt;
/* generated by Query Builder */&lt;BR /&gt;
PROC SQL;&lt;BR /&gt;
   CREATE TABLE WORK.RecentClaims AS &lt;BR /&gt;
   SELECT t1.claim, &lt;BR /&gt;
          t1.LossYr, &lt;BR /&gt;
          t1.ReptYr, &lt;BR /&gt;
          t1.Amount&lt;BR /&gt;
      FROM WORK.RANKEDCLAIMS AS t1&lt;BR /&gt;
      WHERE t1.rank_ReptYr = 1;&lt;BR /&gt;
QUIT;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Tue, 01 Dec 2009 21:57:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/select-max-from-group-of-data/m-p/24098#M3679</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2009-12-01T21:57:16Z</dc:date>
    </item>
    <item>
      <title>Re: select max from group of data</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/select-max-from-group-of-data/m-p/24099#M3680</link>
      <description>Thanks for your help Chris.  I used the Rank Task and it worked great.</description>
      <pubDate>Wed, 02 Dec 2009 14:39:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/select-max-from-group-of-data/m-p/24099#M3680</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-12-02T14:39:18Z</dc:date>
    </item>
  </channel>
</rss>

