BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AJCFreeman
Fluorite | Level 6

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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

7 REPLIES 7
ChrisNZ
Tourmaline | Level 20

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.

PGStats
Opal | Level 21

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
AJCFreeman
Fluorite | Level 6
thanks it worked perfectly
AJCFreeman
Fluorite | Level 6
I did all that to be able to order the data for a Gchart.
however my Gchart doesn't keep that order... 😞
any ideas?
PGStats
Opal | Level 21

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

PG
AJCFreeman
Fluorite | Level 6

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 7 replies
  • 1949 views
  • 3 likes
  • 3 in conversation