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,150

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

🙂

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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