BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
_maldini_
Barite | Level 11

How can I specify certain plot options when using PROC UNIVARIATE? In addition to the typical PROC UNIVARIATE output, I'm seeking a box plot and a histogram w/ a normal line (vertical).

 

Adding the PLOT option to the PROC UNIVARIATE statement provides a horizontal histogram w/o a normal line, a simplifed box plot and a probability plot. 

 

 

	PROC UNIVARIATE DATA=have PLOT; 
	VAR height;
	RUN; 

Adding the HISTOGRAM statement (statement?) and NORMAL option produces a vertical histogram and normal line, but no boxplot.

Proc Univariate Data=have;
     VAR height ;
     Histogram height/normal;
run;

How can I specify just these 2 options? Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

The below code creates a set with some example values and then creates a vertical box plot.

data dummy;
   input value freq;
   do i=1 to freq;
      output;
   end;
datalines;
1 10
2 8
3 11
4 15
5 18
6 2
7 1
;
run;

proc sgplot data= dummy;
   vbox value;
run;
  

View solution in original post

7 REPLIES 7
ballardw
Super User

I would say you'll likely be better off asking for the Boxplot using either Proc SGPLOT or Proc Boxplot if you want a reasonably "pretty" plot.

 

Which version of SAS are you running? There may be options available or not depending on your version.

_maldini_
Barite | Level 11

@ballardw I figured that recomendation would be made. I wanted them both on the same output from the procedure, but that's really just a preference...

 

I'm using SAS University Edition, so 9.4.

 

Thanks for your help.

_maldini_
Barite | Level 11

@ballardw In the examples I've reviewed, the syntax for both Proc SGPLOT and Proc Boxplot includes a BY variable. When I run it w/o  one, I get the following error: "Expecting a *."

 

How should I adjust the syntax to run a boxplot for a single variable? Thanks!

 

 

ballardw
Super User

The below code creates a set with some example values and then creates a vertical box plot.

data dummy;
   input value freq;
   do i=1 to freq;
      output;
   end;
datalines;
1 10
2 8
3 11
4 15
5 18
6 2
7 1
;
run;

proc sgplot data= dummy;
   vbox value;
run;
  
_maldini_
Barite | Level 11

@ballardw Is there a way to produce multiple box plots for multiple variables using this PROC SGPLOT step? I've tried adding multiple variables after the VBOX statement to no avail. I'd like to use just one step to produce all the box plots for my continuous variables....

 

Thanks!

 

 

ballardw
Super User

Your not going to get a simple one line code to display multiple variables in boxplots at one time. You can either call SGPLOT for each variable OR consider transposing you data and using Category to display the original "meaning" of the variable. But that would only work if the ranges of values are similar.

 

Suppose you currently had three variables depicting weight at different measurement periods: WeightIntake WeightMid WeightFinal;

The range of values could well be roughly similar across your data.

So you transpose so that you have

Category              Value

Weight at intake   (the measurement)

Weight at mid period  (the meaurement)

Weight at end       (the measurement)

Then Plot to Value as the varaible and option category=category variable.

 

If you have values with drastically measurement scales you wouldn't want them to display with the box parameters as the variable with a very large range could well compress other variables' appearance to uselessness. Suppose on measure was a persons weight range typicall 0 to 400 pounds or so. And other measure was in microns but had recorded values of 0 to 40000. Displaying both would compress the weight scale to 1 tenth the display area of the micron measurements.

Ksharp
Super User
I don't know how to get this three panel display via proc univariate. But you get it via GTL . Check Rick's blog : http://blogs.sas.com/content/iml/2013/05/08/three-panel-visualization.html

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 6547 views
  • 6 likes
  • 3 in conversation