BookmarkSubscribeRSS Feed
Smile_to_you
Calcite | Level 5

Hello,

 

I have a dataset with thousands of distirbutions different on sample typles. I want to calculate quantiles for each distribution with specific quantile levels stored in a variable. The dataset is basically like this:

 

obs results sample_type pct

1        0.5          A              90

2         0.8          A             90

3        0.4           B              85

4        0.54         A              90

......

 

when I use

 

proc univariate data =mydata;
  var result;
  output out=out_quantile mean = mean pctlpts=pct  pctlpre = p pctlname = _lb _ub ;
  by sample_type;
run;

 

It appears that the option "pctlpts" allows numbers only. you can not assign a variable to it even it is numeric variable.

Is there any ways that I can make it work?

 

Thanks!

 

4 REPLIES 4
ballardw
Super User

PCTLPTS is the option to tell which percentiles you are interested in for all of the VAR variables and all values of the BY variables. If you want the the 10th, 15th and 60th percentiles in your output you use pctlpts= 10 15 60, the PCTLPRE and PCTLNAME are the bits you use to NAME the output variables.

 

You should post some example data, in the form of a datastep, and what you want for output for a small sample. Your example data should include enough values to calculate some of the desired percentiles and include at least 2 of your sample_type values.

 

It almost looks to me as if you may actually want to calculate a whole bunch of percentiles but only keep some of them which would require post processing the result.

Do you have different PCT values for the same Sample_type?

 

IF your PCT values were restricted to 1, 5, 10, 25, 50, 75, 90, 95 and 99 this might be practical in a single call to Proc tabulate but that procedure only does a limited set of percentiles.

 

 

 

 

Smile_to_you
Calcite | Level 5

Thank you! Let me provide more details
Each sample type has a its own distribution and a specfic percentile I am interested in. For example, I want to know 90th
percentile for sample A and 80th percentile for Sample B. The numbers "80", "90" are stored as a variable called "pct". 
Whan I calculate the percentiles, I want to point to that variable instead of directly typing those numbers. 
Is it possible to do that?
@ballardw wrote:

PCTLPTS is the option to tell which percentiles you are interested in for all of the VAR variables and all values of the BY variables. If you want the the 10th, 15th and 60th percentiles in your output you use pctlpts= 10 15 60, the PCTLPRE and PCTLNAME are the bits you use to NAME the output variables.

 

You should post some example data, in the form of a datastep, and what you want for output for a small sample. Your example data should include enough values to calculate some of the desired percentiles and include at least 2 of your sample_type values.

 

It almost looks to me as if you may actually want to calculate a whole bunch of percentiles but only keep some of them which would require post processing the result.

Do you have different PCT values for the same Sample_type?

 

IF your PCT values were restricted to 1, 5, 10, 25, 50, 75, 90, 95 and 99 this might be practical in a single call to Proc tabulate but that procedure only does a limited set of percentiles.

 

 

 

 


 

Reeza
Super User

@Smile_to_you wrote:
Thank you! Let me provide more details Each sample type has a its own distribution and a specfic percentile I am interested in. For example, I want to know 90th percentile for sample A and 80th percentile for Sample B. The numbers "80", "90" are stored as a variable called "pct".  Whan I calculate the percentiles, I want to point to that variable instead of directly typing those numbers.  Is it possible to do that?

Short answer is no, long answer is yes.

As @ballardw indicated you can't specify the list dynamically for different variables, but you can calculate all and then filter out the ones you don't want. 

 

 

Ksharp
Super User
Post some more data would be better. and Post the output you want too.
I think you can try proc ranks.

CODE NOT TESTED
proc ranks data=have groups=100 out=temp;
by sample_type;
var results;
rank rank;
run;
data want;
 set temp;
 if pct=rank;
run;


sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 4528 views
  • 0 likes
  • 4 in conversation