<?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: maximum by group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/re-maximum-by-group/m-p/807672#M318458</link>
    <description>&lt;P&gt;Hi....I am trying to find the maximum frequency&amp;nbsp;grouped by&amp;nbsp;ID and either the same Year or consecutive Years, That is, when the difference in Years is more than 1, then the group by ID and Year is a new group. This is the part that I am stuck on. Any suggestions. Thanks.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
infile datalines dlm=',';
input ID $ Year $ Freq;
datalines; 
1,2015,2
1,2016,5
1,2016,8
1,2018,6
1,2019,4
1,2019,3
1,2020,7
1,2020,3
2,2018,1
2,2018,3
2,2020,4
2,2021,6
;

data want;
infile datalines dlm=',';
input ID $ Year $ Freq max_Freq;
datalines; 
1,2015,2,8
1,2016,5,8
1,2016,8,8
1,2018,6,7
1,2019,4,7
1,2019,3,7
1,2020,7,7
1,2020,3,7
2,2018,1,3
2,2018,3,3
2,2020,4,6
2,2021,6,6
;&lt;/PRE&gt;</description>
    <pubDate>Wed, 13 Apr 2022 20:45:32 GMT</pubDate>
    <dc:creator>twildone</dc:creator>
    <dc:date>2022-04-13T20:45:32Z</dc:date>
    <item>
      <title>re: maximum by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-maximum-by-group/m-p/807672#M318458</link>
      <description>&lt;P&gt;Hi....I am trying to find the maximum frequency&amp;nbsp;grouped by&amp;nbsp;ID and either the same Year or consecutive Years, That is, when the difference in Years is more than 1, then the group by ID and Year is a new group. This is the part that I am stuck on. Any suggestions. Thanks.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
infile datalines dlm=',';
input ID $ Year $ Freq;
datalines; 
1,2015,2
1,2016,5
1,2016,8
1,2018,6
1,2019,4
1,2019,3
1,2020,7
1,2020,3
2,2018,1
2,2018,3
2,2020,4
2,2021,6
;

data want;
infile datalines dlm=',';
input ID $ Year $ Freq max_Freq;
datalines; 
1,2015,2,8
1,2016,5,8
1,2016,8,8
1,2018,6,7
1,2019,4,7
1,2019,3,7
1,2020,7,7
1,2020,3,7
2,2018,1,3
2,2018,3,3
2,2020,4,6
2,2021,6,6
;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Apr 2022 20:45:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-maximum-by-group/m-p/807672#M318458</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2022-04-13T20:45:32Z</dc:date>
    </item>
    <item>
      <title>Re: re: maximum by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-maximum-by-group/m-p/807676#M318462</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data have;
infile datalines dlm=',';
input ID $ Year  Freq;
datalines; 
1,2015,2
1,2016,5
1,2016,8
1,2018,6
1,2019,4
1,2019,3
1,2020,7
1,2020,3
2,2018,1
2,2018,3
2,2020,4
2,2021,6
;

data temp/view=temp;
 set have;
 by id;
 if first.id then group=1;
 if dif(year)&amp;gt;1 then group+1;
run;

proc sql;
  create table want as
  select id, year, freq, max(freq) as max_freq
  from temp
  group by id, group;
quit ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Apr 2022 20:55:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-maximum-by-group/m-p/807676#M318462</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2022-04-13T20:55:22Z</dc:date>
    </item>
    <item>
      <title>Re: re: maximum by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-maximum-by-group/m-p/807680#M318466</link>
      <description>Hi Novinsorin….it worked...thanks for your Help.</description>
      <pubDate>Wed, 13 Apr 2022 21:18:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-maximum-by-group/m-p/807680#M318466</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2022-04-13T21:18:12Z</dc:date>
    </item>
  </channel>
</rss>

