Hi try this function ive written it should be self explantory but let me know if you have any problems. I've only been using R for a few eeeks so apologies if its not the most efficient!
rankit2<-function(rankvar,cuts,data,factor) { ranker<-rankvar ranker<-0 range<-c(1:cuts) range2<-range/cuts range3<-quantile(factor,range2) over<-length(factor) for (i in 1:over){ for (j in 1:cuts) { if (data[[i,1]]<=range3[[j]]) {data[[i,3]]<-j ##test<-j ##print(j) } if (data[[i,3]]>0) break } } out2<-data return(out2) } cars$rank<-0 try2<-rankit2(rank,15,cars,cars$speed) try2 all the best Leigh RCalc partner www.RCalc.co.uk -- View this message in context: http://r.789695.n4.nabble.com/replicating-SAS-s-proc-rank-procedure-tp820510p3924739.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.