Assume a random variable follow normal distribution with mean 10, std 7, and I would like to know the 80 percentile value. I use quantile('normal', 0.8, 10, 7) get 15.89134864. I have a bunch of random variables with different mean and std, and I tried quantile('normal', 0.8, mean, std) but does not work.
data have;
input randvar $1 mean:comma3. std comma3.;
datalines;
a 10 7
b 10 8
c 11 6
; run;
how do I get the table below? Thanks.
randvar | mean | std | pct80 |
a | 10 | 7 | 15.89134864 |
b | 10 | 8 | 16.73296987 |
c | 10 | 6 | 15.0497274 |
Hello @grace999,
Can you be more specific regarding what "does not work"? Please post the log if you get error messages or the results if they are unexpected. Using your dataset HAVE the code below creates the table you want:
data want;
set have;
if randvar='c' then mean+(-1);
pct80=quantile('normal', 0.8, mean, std);
run;
proc print data=want noobs;
format pct80 best11.;
run;
(I used an IF-THEN statement to modify the third mean value according to your table. Maybe it was just a typo.)
Hello @grace999,
Can you be more specific regarding what "does not work"? Please post the log if you get error messages or the results if they are unexpected. Using your dataset HAVE the code below creates the table you want:
data want;
set have;
if randvar='c' then mean+(-1);
pct80=quantile('normal', 0.8, mean, std);
run;
proc print data=want noobs;
format pct80 best11.;
run;
(I used an IF-THEN statement to modify the third mean value according to your table. Maybe it was just a typo.)
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.