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.
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;
The 2025 SAS Hackathon Kicks Off on June 11!
Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.