R code to get percentile

I am a new user for R.. And trying to write a code to calculate percentile as per following sas code...

Proc univariate;
Var X;
By Y;
Out= temp1
PCTLPTS=%SYSEVALF ((100 - Conf Level)/2)
%SYSEVALF((100+ conf Level)/2)
PCTLPRE = X_
PCTLNAME = Lower Upper;

Run;

Conf Level is =95

Welcome to the community!

Percentiles are not unique, they vary per distribution. So your query is not well defined.

However, it's very likely that you are looking for those of normal or t distribution. Take a look at qnorm or qt function.

We prefer to help you guide toward the solution, instead of just doing your work for you. That's why I'm not sharing the exact solution. Please try to use yourself, and in case of any issues, please report back with your attempt and the errors faced, and we will try to help you.

Hope this helps.

1 Like

set.seed(42)

(normdist <- sort(rnorm(1000,mean = 1,sd=1)))
hist(normdist)
plot(1:1000,normdist)
(percentiles_of_normdist <- quantile(normdist,
         probs = (0:100)/100))


(unifdist <- sort(runif(1000,min = 0,max=1)))
hist(unifdist)
plot(1:1000,unifdist)
(percentiles_of_unifdist <- quantile(unifdist,
         probs = (0:100)/100))

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.