Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- Graphics
- /
- How to plot 3D box plot using SAS?

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 08-31-2017 06:59 AM
(1283 views)

Hello everybody,

I want to plot a 3D box blot which illustrates means with standard error bars from calculated data as I show bellow:

All of data, which I have, are numeric type.

How can I do that?

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I have a suggestion, However it is not the best one and needs to be corrected.

```
/* Set the graphics environment */
goptions reset=all cback=white border htext=10pt htitle=12pt;
proc sort data=have;
by x y;
run;
/* Calculate the mean and standard error for each X */
proc means data=have noprint;
by x y;
var z;
output out=meansout mean=mean stderr=stderr;
run;
/* Reshape the data to contain three Y values for */
/* each X for use with the HILOC interpolation. */
data reshape(keep=x y z mean);
set meansout;
z=mean;
output;
z=mean - stderr;
output;
z=mean + stderr;
output;
run;
/* Define the title */
title1 '3D Plot Intraday Volume vs year and Time from Calculated Data';
/* Define the axis characteristics */
axis1 offset=(10,10) minor=none;
axis2 label=(angle=90);
/* Define the symbol characteristics */
symbol1 interpol=hiloctj color=blue line=2;
symbol2 interpol=none color=blue value=dot height=1.5;
/* Plot the error bars using the HILOCTJ interpolation */
/* and overlay symbols at the means. */
proc g3d data=reshape;
scatter x*y=z / size=2 shape='prism';
run;
quit;
```

This program make a bar chart which illustrates means of z vs x and y variables.

7 REPLIES 7

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

How about something more like this instead? You can make two panels of two-dimensional box plots. Here is one way.

```
data x;
do z = 1 to 2;
do x = 1 to 5;
do i = 1 to 100;
y = log(x) + 2 * z + normal(7);
output;
end;
end;
end;
run;
proc sgpanel;
panelby z / columns=1;
vbox y / category=x;
run;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks @WarrenKuhfeld, However simultaneous effects of variables is important.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thats one of those things you can technically do, but really really shouldn't.

3D graphs rarely do a good job of conveying information.

So if you're looking for data to include in a presentation I would suggest an alternative visualization.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Not a Box plot in normal terms. A box plot, or box and whisker shows mean, median, interquartile range [box part] and whiskers out from the box to +/- 1.5 interquartile range for outliers.

If you have SAS Graph then the procedure us Proc G3D. The data set to plot would require the x, y and z value for each point. Getting the series connected as shown would take more than a bit of work to get the correct symbol statements displaying the intended series (upper, lower bound or the value though).

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I have a suggestion, However it is not the best one and needs to be corrected.

```
/* Set the graphics environment */
goptions reset=all cback=white border htext=10pt htitle=12pt;
proc sort data=have;
by x y;
run;
/* Calculate the mean and standard error for each X */
proc means data=have noprint;
by x y;
var z;
output out=meansout mean=mean stderr=stderr;
run;
/* Reshape the data to contain three Y values for */
/* each X for use with the HILOC interpolation. */
data reshape(keep=x y z mean);
set meansout;
z=mean;
output;
z=mean - stderr;
output;
z=mean + stderr;
output;
run;
/* Define the title */
title1 '3D Plot Intraday Volume vs year and Time from Calculated Data';
/* Define the axis characteristics */
axis1 offset=(10,10) minor=none;
axis2 label=(angle=90);
/* Define the symbol characteristics */
symbol1 interpol=hiloctj color=blue line=2;
symbol2 interpol=none color=blue value=dot height=1.5;
/* Plot the error bars using the HILOCTJ interpolation */
/* and overlay symbols at the means. */
proc g3d data=reshape;
scatter x*y=z / size=2 shape='prism';
run;
quit;
```

This program make a bar chart which illustrates means of z vs x and y variables.

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

**If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. **

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.