<?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: Count maximum age in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-maximum-age/m-p/877990#M346879</link>
    <description>&lt;P&gt;having max(age)=age&lt;/P&gt;</description>
    <pubDate>Mon, 29 May 2023 06:23:47 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2023-05-29T06:23:47Z</dc:date>
    <item>
      <title>Count maximum age</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-maximum-age/m-p/877989#M346878</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select sex,age,count(*) as max_agecnt 
from sashelp.class
group by age
having max(age)&amp;gt;=1;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;how to get maximum age count only using proc sql&lt;/P&gt;</description>
      <pubDate>Mon, 29 May 2023 06:13:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-maximum-age/m-p/877989#M346878</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2023-05-29T06:13:03Z</dc:date>
    </item>
    <item>
      <title>Re: Count maximum age</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-maximum-age/m-p/877990#M346879</link>
      <description>&lt;P&gt;having max(age)=age&lt;/P&gt;</description>
      <pubDate>Mon, 29 May 2023 06:23:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-maximum-age/m-p/877990#M346879</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-05-29T06:23:47Z</dc:date>
    </item>
    <item>
      <title>Re: Count maximum age</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-maximum-age/m-p/877992#M346880</link>
      <description>&lt;P&gt;Hi Patrick&lt;/P&gt;
&lt;P&gt;i am not getting required output i want only max age count&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 May 2023 06:59:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-maximum-age/m-p/877992#M346880</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2023-05-29T06:59:48Z</dc:date>
    </item>
    <item>
      <title>Re: Count maximum age</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-maximum-age/m-p/877995#M346881</link>
      <description>&lt;P&gt;You are querying an anwser(how many records have max age) based on another anwser(what is the max age), so inline view is needed.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  select sex, age as max_age, max_age_cnt
  from (
    select sex, age, count(1) as max_age_cnt
    from sashelp.class
    group by sex, age
  )
  group by sex
  having max(age)=age
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The inline view(a quoted query followed "from") anwsers the first question: How many records under different sex and age combinations.&lt;/P&gt;
&lt;P&gt;The out query anwsers the second question: In these combinations, which has the maximum age for different sex?&lt;/P&gt;</description>
      <pubDate>Mon, 29 May 2023 07:39:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-maximum-age/m-p/877995#M346881</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2023-05-29T07:39:02Z</dc:date>
    </item>
    <item>
      <title>Re: Count maximum age</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-maximum-age/m-p/877996#M346882</link>
      <description>&lt;P&gt;And you can have more straight thought:&lt;/P&gt;
&lt;P&gt;Query 1:&amp;nbsp;&lt;SPAN&gt;What is the max age under different sex?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Query 2: How many records have the max age&amp;nbsp;under different sex?&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select distinct a.*, count(b.name) as max_age_cnt
from (
  select sex, max(age) as max_age
  from sashelp.class
  group by sex
) as a
left join sashelp.class as b on a.sex=b.sex and a.max_age=b.age
group by a.sex&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 May 2023 07:43:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-maximum-age/m-p/877996#M346882</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2023-05-29T07:43:14Z</dc:date>
    </item>
    <item>
      <title>Re: Count maximum age</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-maximum-age/m-p/878028#M346889</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Here is one simple query :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
select * from
(select sex,age,count(age) as age_cnt
from age_ds
group by sex,age) a
group by sex
having a.age_cnt=max(a.age_cnt)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 May 2023 12:58:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-maximum-age/m-p/878028#M346889</guid>
      <dc:creator>Pavani_GVL</dc:creator>
      <dc:date>2023-05-29T12:58:42Z</dc:date>
    </item>
    <item>
      <title>Re: Count maximum age</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-maximum-age/m-p/878040#M346893</link>
      <description>&lt;P&gt;You have to first define what "max age count" means.&lt;/P&gt;
&lt;P&gt;Is that the number of cases with the maximum age?&lt;/P&gt;
&lt;P&gt;Perhaps you want one of these answers?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select age,count 
  from (select age,count(*) as count from sashelp.class group by age) 
  having age=max(age)
;
select max_age,sum(age = max_age)
  from (select age,max(age) as max_age from sashelp.class) 
  group by max_age
;
select sex,max_age,sum(age = max_age)
  from (select sex,age,max(age) as max_age from sashelp.class)
  group by sex,max_age 
;
select sex,max_age,sum(age = max_age)
  from (select sex,age,max(age) as max_age from sashelp.class group by sex)
  group by sex,max_age
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_1-1685369803180.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/84431i6088E90F05B6235A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_1-1685369803180.png" alt="Tom_1-1685369803180.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Is that the age with the maximum number of cases?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Perhaps you want one of these answers.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
 select age,count from (select age,count(*) as count from sashelp.class group by age)
   having count=max(count)
 ;
 select sex,age,count from (select sex,age,count(*) as count from sashelp.class group by sex,age)
   having count=max(count)
 ;
 select sex,age,count from (select sex,age,count(*) as count from sashelp.class group by sex,age)
   group by sex
   having count=max(count)
 ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV id="tinyMceEditorTom_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_2-1685369880410.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/84432i6D8084D1C35FD26B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_2-1685369880410.png" alt="Tom_2-1685369880410.png" /&gt;&lt;/span&gt;&lt;/P&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>Mon, 29 May 2023 14:18:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-maximum-age/m-p/878040#M346893</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-29T14:18:13Z</dc:date>
    </item>
  </channel>
</rss>

