Friends:
Does SAS have a function that does the work of excel's rank.avg. The work I'm doing using this specific function and I would like to be able to manipulate the data I currently have in SAS without having to cross platforms and re-load the data back into SAS.
Let's say there are ~150 observations in the dataset. Each has unique column observations by year (i.e. _2015_expenditures) with each row being a different department. I want to use the "rank.avg" function to rank these specific departments (in ascending rank order) by their yearly expenditure columns individually into a new variable (that shows the numeric rank.avg values).
Excel's "RANK.AVG" function is summarized as: "Returns the rank of a number in a list of numbers: its size relative to other values in the list; if more than one value has the same rank, the average rank is returned."
Thanks in advance!
Proc rank with a By Year, or what ever your variable name is, is likely a much better way then attempting by data step. For one thing there are multiple ways to address ties.
To answer your first question: Stubbornness, I suppose. I'll gladly pursue the proc rank approach if I can get it to do what I need. Thank you for your suggestion.
I need, essentially, 50 columns of data (10 columns x five years total). Each of the data points are critical for their own purposes as I intend to index them later. There are 10 total measures over the course of five years. There's a 131 total departments (row data). The column data is what I need ranked.
Currently, my proc rank would look something like this?
proc rank data=have out=want descending;
var _2015_se_expend /*_2016_se_expend _2017_se_expend _2018_se_expend _2019_se_expend*/;
ranks _2015_rankavg_se_expend;
run;
When I run this, my 2015 column data is ranked correctly. My question then, at this point, is how do I get the commented variables into the mix to have those variables ranked by year in the same manner as 2015? I need all of the annual column data ranked just as I did the first.
Please post an excerpt of the data you have in usable form, so that we don't have to guess what might work in your case.
When i see variables named like _2015_se_expend, _2016_se_expend, _2017_se_expend ... i always tend to fix the miss-shaped data first. Then you could use something like
proc rank data= work.transposed out=work.ranked descending;
by year;
var se_expend;
ranks se_expand_ranked;
run;
If you do not want to use the very sensible suggestion from @andreas_lds (add a YEAR variable and reduce the number of variables to be ranked), it should be quite easy to do what you want like this:
proc rank data=have out=want descending;
var _2015_se_expend _2016_se_expend _2017_se_expend _2018_se_expend
_2019_se_expend;
ranks _2015_rankavg_se_expend _2016_rankavg_se_expend _2017_rankavg_se_expend _2018_rankavg_se_expend _2019_rankavg_se_expend;
run;
Thanks.
Last thing, I think:
In proc rank, is there a way to assign all "ties" with the average value of the group followed by the next available number? For example, the seven numbers 10, 8, 8, 4, 4, 4, 2 would be ranked 7, 5.5, 5.5, 3, 3, 3, 1?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.