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

Showing results for

Find a Community

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

08-31-2017 06:59 AM - edited 08-31-2017 07:03 AM

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?

Accepted Solutions

Solution

09-06-2017
02:59 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to aminkarimid

08-31-2017 06:28 PM

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.

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to aminkarimid

08-31-2017 09:58 AM - edited 08-31-2017 11:02 AM

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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to WarrenKuhfeld

08-31-2017 06:19 PM - edited 08-31-2017 06:32 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to aminkarimid

08-31-2017 06:27 PM

Since you're not displaying 3 variables, a single line series plot with the high/low bars will communicate the information in a more efficient manner.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to aminkarimid

08-31-2017 10:45 AM

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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Reeza

08-31-2017 06:32 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to aminkarimid

08-31-2017 02:17 PM

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

Solution

09-06-2017
02:59 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to aminkarimid

08-31-2017 06:28 PM

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.