BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
benvar
Fluorite | Level 6

I have a dataset for which I want to know the p25, p50, and p75 (and maybe other) percentiles for var1 (first variable) when the data is grouped by var2 (second variable).  I was able to do this using PROC UNIVARIATE but I then lose my original data once I output from PROC UNIVARIATE.  Is there a way to calculate the percentiles and merge it back with my original dataset? 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Here's an illustration of two different methods:

https://github.com/statgeek/SAS-Tutorials/blob/master/add_average_value_to_dataset.sas

 

Another option, if you're trying to bin groups with percentiles is to use the RANK procedure instead.

 


@benvar wrote:

I have a dataset for which I want to know the p25, p50, and p75 (and maybe other) percentiles for var1 (first variable) when the data is grouped by var2 (second variable).  I was able to do this using PROC UNIVARIATE but I then lose my original data once I output from PROC UNIVARIATE.  Is there a way to calculate the percentiles and merge it back with my original dataset? 


 

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Example:

 

proc summary data=have nway;
    class var2;
    var var1;
    output out=pctiles p25=p25 p50=p50 p75=75;
run;
proc sort data=have;
    by var2;
run;
data want;
    merge have pctiles;
    by var2;
run;
--
Paige Miller
Astounding
PROC Star

You can't attach it as part of PROC UNIVARIATE.  Run that first, then put the results back onto your original data set ... either MERGE by VAR2, or use SQL, matching on VAR2.

Reeza
Super User

Here's an illustration of two different methods:

https://github.com/statgeek/SAS-Tutorials/blob/master/add_average_value_to_dataset.sas

 

Another option, if you're trying to bin groups with percentiles is to use the RANK procedure instead.

 


@benvar wrote:

I have a dataset for which I want to know the p25, p50, and p75 (and maybe other) percentiles for var1 (first variable) when the data is grouped by var2 (second variable).  I was able to do this using PROC UNIVARIATE but I then lose my original data once I output from PROC UNIVARIATE.  Is there a way to calculate the percentiles and merge it back with my original dataset? 


 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 2029 views
  • 0 likes
  • 4 in conversation