Data visualization with SAS programming

box plots and histogram

Reply
Contributor
Posts: 25

box plots and histogram

Due to user complain the difficulty about understanding the meaning of box plot, I ‘translate’ the box plot to histogram. Why the chref=green and whref=3 don’t work in proc univariate? Is there better way to do this?

/*Generate box plot: options must have*/
ods pdf  file="&pdfout\box.pdf"  notoc;  
	title; 
	ods graphics / reset=all height=2.7 in width=4.3in;
	ods graphics on / border = off;
	ods graphics on / imagemap=on;
	Title1 h=1.4 j=c font=Arial bold "Age Summary - box";

	proc sgplot data=class; 
	hbox age;  
		refline &ag1 /axis=x  
		lineattrs=(color=green thickness=3) 
		label=("&nm1: &ag1") labelloc=inside;
	run; quit;
ods pdf close;

/*Generate histogram*/
ods pdf  file="&pdfout\hist.pdf"  notoc;  
	title; 
	ods graphics / reset=all height=2.7 in width=4.3in;
	ods graphics on / border = off;
	ods graphics on / imagemap=on;
	Title1 h=1.4 j=c font=Arial bold "Age Summary - hist";
	
	proc univariate data=sashelp.class noprint;
   	histogram age / midpoints = 10 to 20 by 1
             rtinclude
			 href=&ag chref=green  whref=3 hreflabel="&nm1: &ag1"
             outhistogram = OutMdpts;
	run; quit;
ods pdf close;

 

 

SAS Super FREQ
Posts: 1,042

Re: box plots and histogram

Those options on UNIVARIATE might only work with GRSEG-based output. SGPLOT also has a HISTOGRAM statement, and you can overlay REFLINEs behind or in front of the histogram. You can also control the attributes of the REFLINEs. Here is a simple example:

 

proc sgplot data=sashelp.heart;
histogram cholesterol;
refline 200 / axis=x lineattrs=(color=red thickness=2);
refline 300 / axis=x lineattrs=(color=green thickness=2);
run;
Contributor
Posts: 25

Re: box plots and histogram

Thank you very much. This refline seems a little bit of misleading. What I really need is an indicator to highlight the cross point of age and percent for a student, for example to indicate Carol belongs to 20% distribution group, not necessary a refline. The indicator label should be like “Carol: 14”. Welcome suggestion or creation.

proc sql noprint; select name, age into :nm, :ag from sashelp.class where name="Carol"; quit;
%let ag1=&ag; %let nm1=&nm;

proc sgplot data=sashelp.class;
	histogram age ;
	refline &ag / axis=x label ="&nm1: &ag1" labelloc=inside
	lineattrs=(color=green thickness=2);
run;
SAS Super FREQ
Posts: 1,042

Re: box plots and histogram

I'm not quite sure of what you need. Can you post a picture?

Contributor
Posts: 25

Re: box plots and histogram

It was so nice to meet you in person around the SAS Global Forum 2018. I agree with your explanation, i.e., the 'translation' doesn't work well. Thank you.  By the way the supper demo is great, and I am thinking to attend in 2019. Hopefully see you there!

Ask a Question
Discussion stats
  • 4 replies
  • 121 views
  • 0 likes
  • 2 in conversation