BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DmytroYermak
Lapis Lazuli | Level 10

Hi all,

 

I have the following training data:

data test;
  infile datalines dlm="," dsd;
  input severity @@;
datalines;                      
0,0,0,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,3,3,3,3,4,4,5,5,5,5,6,7,9,10,11
;
run;

How to built a distribution histogram with visualisation of Median and percentiles using proc univariate.

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

Your histogram is already displaying zero values. The first bin displays the counts of all values in the half-open interval [0, 2).

That fact might be clearer if you use the ENDPOINTS option to display the endpoints of the bins instead of the midpoints:

histogram severity / href=(2.0 1.0 7.0) endpoints;

 

You can also change the default bin widths and locations, if necessary.  

View solution in original post

8 REPLIES 8
PaigeMiller
Diamond | Level 26

If it has to be done in PROC UNIVARIATE, I think you can't do that. If you want to do this in PROC UNIVARIATE followed by PROC SGPLOT, then it's pretty simple.

--
Paige Miller
Reeza
Super User

How would you want the graph to look? AFAIK, that isn't a standard histogram and how you identify the percentiles and median can vary.

Rick_SAS
SAS Super FREQ

You didn't say which percentiles you want, but her is how to do it with the 10th and 90th percentiles:

 

proc means data=test median p10 p90;
var severity;
run;

proc univariate data=test;
var severity;
histogram severity / href=(2.0 1.0 7.0);
inset P10 median P90 / position=NE;
run;

If you prefer the 5th and 95th percentiles, use P5 and P95 in the program.

DmytroYermak
Lapis Lazuli | Level 10

Thank you, Rick. I have added the "normal" option to see the normal plot approximation(sorry for "my terminology"). I have just one question: how to output "zero" values on the histogram as well2.jpg

Rick_SAS
SAS Super FREQ

Your histogram is already displaying zero values. The first bin displays the counts of all values in the half-open interval [0, 2).

That fact might be clearer if you use the ENDPOINTS option to display the endpoints of the bins instead of the midpoints:

histogram severity / href=(2.0 1.0 7.0) endpoints;

 

You can also change the default bin widths and locations, if necessary.  

DmytroYermak
Lapis Lazuli | Level 10
Well, how to set up the same interval that we have in our dataset [0,1)?
Rick_SAS
SAS Super FREQ

The last line in my previous message links to an article that explains everything.

DmytroYermak
Lapis Lazuli | Level 10
Thank you! That is what I was looking for!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 3047 views
  • 3 likes
  • 4 in conversation