BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ArseneW
Calcite | Level 5

Hello,

 

Is there a possibility to write one sql querry in sas that will show max of count?

Let's say I have below data, I'm looking for user (USER_ID) with max number of rows and I would like to know this count number

ID_ITEMID_USERDATE_FROMDATE_TO
4713.10.201825.10.2018
6916.08.201825.08.2018
6321.07.201803.08.2018
8401.10.201803.10.2018
7930.08.201808.09.2018
6223.08.201827.08.2018
2410.09.201818.09.2018
5808.10.201818.10.2018
9316.08.201826.08.2018
6620.08.201801.09.2018
5909.10.201813.10.2018
71117.09.201828.09.2018
10920.08.2018 
2307.08.201809.08.2018
9125.07.201804.08.2018
10707.10.201813.10.2018
8727.08.201830.08.2018
4511.10.201820.10.2018
4130.07.201809.08.2018
7403.09.201813.09.2018
4826.09.2018 
7128.07.201801.08.2018
8512.09.201818.09.2018
8502.09.201813.09.2018
6609.08.201810.08.2018
1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @ArseneW and welcome to the SAS Support Communities!

 

Use an inline view:

proc sql;
create table want as
select *
from (select id_user, count(*) as cnt from have group by id_user)
having cnt=max(cnt);
quit;

View solution in original post

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post test data in the form of a datastep:

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

As such not tested:

proc sql;
  create table want as
  select id_user
  from   have
  group by id_user
  having count(*)=max(count(*));
quit;

                         

Note that if there are more than one with the total number of records these will all come out.

FreelanceReinh
Jade | Level 19

Hello @ArseneW and welcome to the SAS Support Communities!

 

Use an inline view:

proc sql;
create table want as
select *
from (select id_user, count(*) as cnt from have group by id_user)
having cnt=max(cnt);
quit;