DATA Step, Macro, Functions and more

ranking and changing the order of tie values

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

ranking and changing the order of tie values

[ Edited ]

Hi,

I am ranking companies based on a metric. However when I have a tie between my company and another one, I want my company to show up first. How do I do that?

 


Accepted Solutions
Solution
‎06-10-2016 09:37 AM
Respected Advisor
Posts: 4,919

Re: ranking and changing the order of tie values

Posted in reply to AJCFreeman

You can define a new variable and add it to the table sorting order

 

data have;
input Cpny :$10. Metric;
datalines;
Company_1 1
Company_2 2
MyCompany 2
Company_3 3
;

data have_report;
set have;
order = cpny ne "MyCompany";
run;

/* List companies in descending order of my metric, but
 show MyCompany first in case of a tie. Other ties are sorted 
 by alphabetical order of company name. */
proc sql;
select cpny, metric
from have_report
order by metric desc, order, cpny;
quit;
PG

View solution in original post


All Replies
PROC Star
Posts: 1,759

Re: ranking and changing the order of tie values

Posted in reply to AJCFreeman

I suppose your rank value is an integer. Just always add 0.1 point to your company's rank and it will be ahead in case of ties.

Solution
‎06-10-2016 09:37 AM
Respected Advisor
Posts: 4,919

Re: ranking and changing the order of tie values

Posted in reply to AJCFreeman

You can define a new variable and add it to the table sorting order

 

data have;
input Cpny :$10. Metric;
datalines;
Company_1 1
Company_2 2
MyCompany 2
Company_3 3
;

data have_report;
set have;
order = cpny ne "MyCompany";
run;

/* List companies in descending order of my metric, but
 show MyCompany first in case of a tie. Other ties are sorted 
 by alphabetical order of company name. */
proc sql;
select cpny, metric
from have_report
order by metric desc, order, cpny;
quit;
PG
Occasional Contributor
Posts: 6

Re: ranking and changing the order of tie values

thanks it worked perfectly
Occasional Contributor
Posts: 6

Re: ranking and changing the order of tie values

Posted in reply to AJCFreeman
I did all that to be able to order the data for a Gchart.
however my Gchart doesn't keep that order... :-(
any ideas?
Respected Advisor
Posts: 4,919

Re: ranking and changing the order of tie values

Posted in reply to AJCFreeman

Create a sorted version of your dataset, switch to a SGPLOT VBAR (or HBAR) plot, and use XAXIS (or YAXIS) option DISCRETEORDER=DATA.

PG
Occasional Contributor
Posts: 6

Re: ranking and changing the order of tie values

I put a space in front of my company's name.

PROC Star
Posts: 1,759

Re: ranking and changing the order of tie values

Posted in reply to AJCFreeman
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 411 views
  • 3 likes
  • 3 in conversation