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 5,771

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; 

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:



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;
data _null_;
set out;
call symput('mean',mean);
proc univariate data=sashelp.class noprint;
var height;
histogram height / href=&mean hreflabel='Average'; run;


For more information and other tips: 



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).   


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


Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.


Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Tags