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!
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;
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.
@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.
@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!
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;
@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!
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.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.