BookmarkSubscribeRSS Feed

How to add a vertical reference line to PROC UNIVARIATE histograms - the STATREF options

Started ‎05-12-2021 by
Modified ‎05-12-2021 by
Views 6,997

1st - The easiest way:

If you want to use HIST in your PROC UNIVARIATE procedure and add a vertical line corresponding to the mean of your variable, here is a straightforward way:

 

proc univariate data=sashelp.class noprint;
var height;
histogram height / normal(color=big w=2) statref=mean cstatref=crimson wstatref=2; 
run;

STATREF = allows you to choose which computed value will become your reference line
CSTATREF = allows you to choose the color of your stat reference line

WSTATREF = allows you to choose the width of your stat reference line

Note that I did not find "WSTATREF =" in any SAS document at this stage, I just tried it.

 

This will give you something that looks like:

WhyWhy_0-1620849260321.png

 

2nd - A much more generalizable way with many lines of codes:

Here is a way you can find over the internet, and that would be provided by SAS technical support. You can imagine as well to use such approach with other SAS plotting procedures.

proc means data=sashelp.class noprint;
var height;
output out=out mean=mean;
run;
 
data _null_;
set out;
call symput('mean',mean);
run;
 
proc univariate data=sashelp.class noprint;
var height;
histogram height / href=&mean hreflabel='Average'; run;

 

For more information and other tips:

https://blogs.sas.com/content/iml/2020/04/13/horizontal-vertical-reference-lines-sas.html 

 

Comments

Good example. Do you have an example showing how to add a reference line in univariate histogram that is not based on a statistic? for example, if I want to show a line at 68, which is the upper spec limit provide by my customer.  

Just use href=68 instead of statref=mean.

Or if you want to have more ref lines: e.g. href=(68 4711).   

🙂

Contributors
Version history
Last update:
‎05-12-2021 04:51 PM
Updated by:

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

SAS AI and Machine Learning Courses

The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.

Get started

Article Tags