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;
Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!
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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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