I am having trouble ranking a variable within groups. Here is my code: proc rank data=MONTHRANK out=FLAGRANK ties=dense; /* Ranking UseFlag within each month with TIES=DENSE */
by ID TYPE descending MonthGroup NumUseFlag;
var NumUseFlag;
ranks FlagRank;
run; Here is the initial table data MONTHRANK;
length ID $12 Type $3 AdjustmentCode MonthGroup MonthRank NumUseFlag 8
;
infile datalines dsd truncover;
input ID -- NumUseFlag;
datalines;
123AAABBBC,001,,14,1,1
123AAABBBC,001,3,13,1,0
123AAABBBC,001,2,13,2,1
123AAABBBC,001,,13,3,1
123AAABBBC,001,26,12,1,1
123AAABBBC,001,,12,2,1
123AAABBBC,001,,11,1,1
123AAABBBC,001,,10,1,1
; Here is what I want to output data MONTHRANK_OUTPUT;
length ID $12 Type $3 AdjustmentCode MonthGroup MonthRank NumUseFlag FlagRank 8
;
infile datalines dsd truncover;
input ID -- FlagRank;
datalines;
123AAABBBC,001,,14,1,1,1
123AAABBBC,001,3,13,1,0,1
123AAABBBC,001,2,13,2,1,1
123AAABBBC,001,,13,3,1,2
123AAABBBC,001,26,12,1,1,1
123AAABBBC,001,,12,2,1,2
123AAABBBC,001,,11,1,1,1
123AAABBBC,001,,10,1,1,1
; Sorry if the code isn't exactly correct, I hope this is clear enough. The error I am getting is "ERROR: Data set WORK.MONTHRANK is not sorted in ascending sequence. The current BY group has NumUseFlag = 1 and the next BY group has NumUseFlag = 0.", which kind of makes sense to me if there were another adjustment line above the line in the 13th month with the NumUseFlag = 1 instead of 0 and the AdjustmentCode = 26 (this is possible within the rest of the data), but I don't really see why that should necessarily matter and I'm unsure of how to get around the issue. I have tried using descending, but I get the same error just saying it's not sorted in descending sequence. I have also tried using CLASS, but I don't think it works with PROC RANK.
... View more