I have a dataset with a Key and a number of scores for different factors (A,B,C,D...). It looks something like this:
data scores;
input KEY A B C D E F G H;
cards;
1 1 2 4 4 4 9 9 7
2 1 2 3 4 5 6 7 8
3 7 8 9 9 6 5 5 4
4 4 9 9 7 7 8 5 1
run;
I'm trying to get a ranking of each factor that looks something like the output of this:
proc sql;
create table scorerank as
select *
,(ordinal(1,A,B,C,D,E,F,G,H)) as ScoreRank1
,(ordinal(2,A,B,C,D,E,F,G,H)) as ScoreRank2
,(ordinal(3,A,B,C,D,E,F,G,H)) as ScoreRank3
,(ordinal(4,A,B,C,D,E,F,G,H)) as ScoreRank4
,(ordinal(5,A,B,C,D,E,F,G,H)) as ScoreRank5
,(ordinal(6,A,B,C,D,E,F,G,H)) as ScoreRank6
,(ordinal(7,A,B,C,D,E,F,G,H)) as ScoreRank7
,(ordinal(8,A,B,C,D,E,F,G,H)) as ScoreRank8
from scores;
quit;
My problem is that there is a dynamic number of factors every time. Which means, a dynamic list within the ordinal function and a ScoreRankX that goes up to the count of Scores.
I have tried to do this as a start:
%let num = 8;
%let factors = A,B,C,D,E,F,G,H;
data datarank;
set scores;
do i = 1 to &num.;
ScoreRank&num. = (ordinal(&num.,&factors.));
end;
run;
I'm OK to change the %let statements at the start of each code, but i'm trying to make the ranking part more automatic. Any idea of how I can improve the above code that I am working on? Currently it outputs incorrectly with just the last rank and "i" (even though I have the do loop in?).
Any help much appreciated.

