BookmarkSubscribeRSS Feed
mahibhu
Calcite | Level 5

hi need quick help!

 

if i need to get the top% & bottom 10% by each group.

 

can you please give me some solution with example.

 

Thanks Inadvance

Mahendra

2 REPLIES 2
ChrisHemedinger
Community Manager

Here's one way, using PROC RANK -- tailor made for problems like this.  The RANK procedure can assign ranks by decile (groups=10), so rank=0 is the lowest 10%, and rank=9 is the highest 10%.  Here's an example with the CARS data.

 

proc sort
	data=sashelp.cars
	out=work.sortedcars
	;
	by origin;
run;

proc rank data = work.sortedcars
	groups=10
	ties=mean
	out=top_bottom;
	by origin;
	var msrp;
ranks ranked_msrp ;
run;

title "top 10% in each group";
proc print data=top_bottom;
 var origin make model msrp;
 where ranked_msrp = 9;
 by origin;
run;

title "bottom 10% in each group";
proc print data=top_bottom;
 var origin make model msrp;
 where ranked_msrp = 0;
 by origin;
run;
SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
mkeintz
PROC Star

Take a look at documentation on  PROC RANK.  You'll probably want to set the GROUPS=10 option.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2111 views
  • 1 like
  • 3 in conversation