Specifying options for plots using PROC UNIVARIATE (Box plot, Histogram)

Solved
Regular Contributor
Posts: 202

Specifying options for plots using PROC UNIVARIATE (Box plot, Histogram)

[ Edited ]

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!

Accepted Solutions
Solution
‎04-26-2016 06:54 PM
Super User
Posts: 13,528

Re: Specifying options for plots using PROC UNIVARIATE (Box plot, Histogram)

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;
``````

All Replies
Super User
Posts: 13,528

Re: Specifying options for plots using PROC UNIVARIATE (Box plot, Histogram)

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.

Regular Contributor
Posts: 202

Re: Specifying options for plots using PROC UNIVARIATE (Box plot, Histogram)

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

Regular Contributor
Posts: 202

Re: Specifying options for plots using PROC UNIVARIATE (Box plot, Histogram)

@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!

Solution
‎04-26-2016 06:54 PM
Super User
Posts: 13,528

Re: Specifying options for plots using PROC UNIVARIATE (Box plot, Histogram)

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;
``````
Regular Contributor
Posts: 202

Re: Specifying options for plots using PROC UNIVARIATE (Box plot, Histogram)

@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!

Super User
Posts: 13,528

Re: Specifying options for plots using PROC UNIVARIATE (Box plot, Histogram)

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.

Super User
Posts: 10,778

Re: Specifying options for plots using PROC UNIVARIATE (Box plot, Histogram)

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
🔒 This topic is solved and locked.