BookmarkSubscribeRSS Feed
nnl3256
Obsidian | Level 7

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;

 

 

4 REPLIES 4
DanH_sas
SAS Super FREQ

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;
nnl3256
Obsidian | Level 7

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;
DanH_sas
SAS Super FREQ

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

nnl3256
Obsidian | Level 7

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!

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 2366 views
  • 0 likes
  • 2 in conversation