Hi SAS experts,
I create percentile of var1 using the following code. However, the number of observation in the top 90 percentile or bottom 10 percentile does not equal to 10% of the total observation. May I ask is there an error in my code ? Thanks!
proc univariate data = tmp1 noprint;
by date;
var var1;
output out = ret_cuts pctlpre=retp_ pctlpts=10,90;
run;
Your code looks fine to me? Changing the data set and variables to SAS data sets we can all access yields a correct result?
proc univariate data = sashelp.iris noprint;
by species;
var sepallength;
output out = ret_cuts pctlpre=retp_ pctlpts=10,90;
run;
@PeterClemmensenThanks for your reply.
I might have a lot of values of variable equal to the 90 percent cut off value. Could this be the reason why number of observation above 90 percentile larger than 10% of total observation ? May I ask how to increase the number of digit in the variable of interest, so that the precision will increase ?
Thanks
@Nieves wrote:
I might have a lot of values of variable equal to the 90 percent cut off value. Could this be the reason why number of observation above 90 percentile larger than 10% of total observation ?
Yes, this is a plausible reason.
@Nieves wrote:
May I ask how to increase the number of digit in the variable of interest, so that the precision will increase ?
How do you select the observations from the top and bottom decile? Normally, this selection would be based on the internal values of the variable of interest. Hence, the full precision would be used and no "hidden digits" would be left to serve as tie breakers. Can you obtain more precise values from the data source? Could another variable serve as a tie breaker? Or would it make sense for your application to take a random sample from the (identical) values at the cutoff in order to get as close to a 10% subset as possible?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.