🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 12-18-2018 04:25 AM
(14675 views)
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_ITEM | ID_USER | DATE_FROM | DATE_TO |
4 | 7 | 13.10.2018 | 25.10.2018 |
6 | 9 | 16.08.2018 | 25.08.2018 |
6 | 3 | 21.07.2018 | 03.08.2018 |
8 | 4 | 01.10.2018 | 03.10.2018 |
7 | 9 | 30.08.2018 | 08.09.2018 |
6 | 2 | 23.08.2018 | 27.08.2018 |
2 | 4 | 10.09.2018 | 18.09.2018 |
5 | 8 | 08.10.2018 | 18.10.2018 |
9 | 3 | 16.08.2018 | 26.08.2018 |
6 | 6 | 20.08.2018 | 01.09.2018 |
5 | 9 | 09.10.2018 | 13.10.2018 |
7 | 11 | 17.09.2018 | 28.09.2018 |
10 | 9 | 20.08.2018 | |
2 | 3 | 07.08.2018 | 09.08.2018 |
9 | 1 | 25.07.2018 | 04.08.2018 |
10 | 7 | 07.10.2018 | 13.10.2018 |
8 | 7 | 27.08.2018 | 30.08.2018 |
4 | 5 | 11.10.2018 | 20.10.2018 |
4 | 1 | 30.07.2018 | 09.08.2018 |
7 | 4 | 03.09.2018 | 13.09.2018 |
4 | 8 | 26.09.2018 | |
7 | 1 | 28.07.2018 | 01.08.2018 |
8 | 5 | 12.09.2018 | 18.09.2018 |
8 | 5 | 02.09.2018 | 13.09.2018 |
6 | 6 | 09.08.2018 | 10.08.2018 |
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Post test data in the form of a datastep:
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;