BookmarkSubscribeRSS Feed
animesh123
Obsidian | Level 7

I have this small code .Could anyone please help me how to limit TOP 10 highest transaction.

proc sql;
select make,origin,invoice
from sashelp.cars
group by make,origin
order by make, invoice desc;
run;
quit;

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Question is asked often: 

 

https://communities.sas.com/t5/New-SAS-User/Select-top-N-from-each-group-in-proc-sql/m-p/852214


Generally, I think you would be better off using PROC RANK that SQL as PROC RANK allows you to handle ties in different ways. And just plain old PROC SORT is much easier to code than using SQL.

--
Paige Miller
Ksharp
Super User
proc sql;
create table want as
select a.make,a.origin,a.invoice
from sashelp.cars as a left join sashelp.cars as b
 on a.make=b.make and a.origin=b.origin and a.invoice<=b.invoice
group by a.make,a.origin,a.invoice
having count(distinct b.invoice) in (1:10)
order by make, invoice desc;
quit;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 698 views
  • 2 likes
  • 3 in conversation