turn on suggestions

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
- /
- General Programming
- /
- Boxplot (Multiple variables)

Topic Options

- 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
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-22-2014 08:36 PM

Hello, I am trying to create a boxplot image with several variables side-by-side. These are not categories of the same variable but, rather, separate continuous variables in which I would like a side-by-side comparison of the boxplots. These variables all share the same range (% out of 100) and I wish to use a single boxplot image to display several boxplots side-by-side.

So far, I have generated separate boxplot images using the vbox statement in the sgplot procedure to make individual boxplot images, but I havn't found anything to combine them into a single image.

Let me know if my description is not clear

Thanks!

Accepted Solutions

Solution

09-23-2014
11:08 AM

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

09-23-2014 11:08 AM

See the article Order variables by values of a statistic - The DO Loop, which also sorts the variables according to some statistic.

If you don't care about sorting the box plots, you can skip the first few steps. Just add an ID variable, call PROC TRANSPOSE, , call PROC SGPLOT and use the VBOX statement with the CATEGORY= option.

All Replies

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

09-22-2014 10:48 PM

Combine all the continuous variables in one variable and flag them. Then use flag as a categorical variable on x-axis to display boxplots of continuous variables side-by-side.

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

09-23-2014 04:50 PM

Could you please provide an example?

How would you combine several categorical variables into one?

Example.

X1 X2 X3

obs1 1 5 3

obs2 2 4 5

combine

Y1

obs1 1, 5, 3

obs2 2, 4, 5

please provide example of how to flag as well. Thanks!

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

09-23-2014 05:17 PM

Please see an example below.

data class(keep=all_vars flag);

set sashelp.class;

array v{*} _numeric_;

do i=1 to dim(v);

all_vars=v{i};

flag=vname(v{i});

output;

end;

run;

proc sort data=class;

by flag;

run;

proc boxplot data = class;

plot all_vars * flag;

quit;

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

09-24-2014 10:33 AM

The blog post does contain an example.

Solution

09-23-2014
11:08 AM

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

09-23-2014 11:08 AM

See the article Order variables by values of a statistic - The DO Loop, which also sorts the variables according to some statistic.

If you don't care about sorting the box plots, you can skip the first few steps. Just add an ID variable, call PROC TRANSPOSE, , call PROC SGPLOT and use the VBOX statement with the CATEGORY= option.

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

11-14-2014 03:48 AM

Thanks Rick! I am still getting accustomed to the SAS language so it took me a while to figure out the code. The graph looks great!

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

09-23-2014 05:41 PM