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?
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;
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.
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;
Create a sorted version of your dataset, switch to a SGPLOT VBAR (or HBAR) plot, and use XAXIS (or YAXIS) option DISCRETEORDER=DATA.
I put a space in front of my company's name.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.