Data visualization with SAS programming

box plots on same axis

Reply
New Contributor
Posts: 3

box plots on same axis

Hello I am given data such as 

 

state 1985 1996 2002

1         73      45     57

2         82      36     48

3         91      29     35

4         74      10     49

 

etc. 

 

I can create box plots of 1985, 1996 and 2002 seperately.

 

I use proc sgplot data = mydata;

vbox 1985;

run;

 

and I do that for the other years as well, I am attempting to get box plots for all 3 years in the same axis or the same graph. 

I have tried proc sgpanel as well as proc box plot with no luck. 

I am not sure if I need to perhaps combine the 3 variables into 1 category or group and then do a paneled box plot. 

 

Help would be greatly appreciated. 

 

Super User
Posts: 19,080

Re: box plots on same axis

[ Edited ]

 

Transpose your data so you can specify the CATEGORY=YEAR. 

 

Post what your code looks like if you're having issues.

 

Here's an example that's broader than yours:

http://support.sas.com/rnd/datavisualization/yourGraphs/analyticalQuick/vbox/#s1=1

 

The SASHELP.CARS data set is available on almost all SAS installations.  

 


Steelz91 wrote:

Hello I am given data such as 

 

state 1985 1996 2002

1         73      45     57

2         82      36     48

3         91      29     35

4         74      10     49

 

etc. 

 

I can create box plots of 1985, 1996 and 2002 seperately.

 

I use proc sgplot data = mydata;

vbox 1985;

run;

 

and I do that for the other years as well, I am attempting to get box plots for all 3 years in the same axis or the same graph. 

I have tried proc sgpanel as well as proc box plot with no luck. 

I am not sure if I need to perhaps combine the 3 variables into 1 category or group and then do a paneled box plot. 

 

Help would be greatly appreciated. 

 


 

New Contributor
Posts: 3

Re: box plots on same axis


Reeza wrote:

 

Transpose your data so you can specify the CATEGORY=YEAR. 

 

Post what your code looks like if you're having issues.

 

Here's an example that's broader than yours:

http://support.sas.com/rnd/datavisualization/yourGraphs/analyticalQuick/vbox/#s1=1

 

The SASHELP.CARS data set is available on almost all SAS installations.  

 


Steelz91 wrote:

Hello I am given data such as 

 

state 1985 1996 2002

1         73      45     57

2         82      36     48

3         91      29     35

4         74      10     49

 

etc. 

 

I can create box plots of 1985, 1996 and 2002 seperately.

 

I use proc sgplot data = mydata;

vbox 1985;

run;

 

and I do that for the other years as well, I am attempting to get box plots for all 3 years in the same axis or the same graph. 

I have tried proc sgpanel as well as proc box plot with no luck. 

I am not sure if I need to perhaps combine the 3 variables into 1 category or group and then do a paneled box plot. 

 

Help would be greatly appreciated. 

 


 


My current code looks like this

 

proc import datafile="/folders/myfolders/sasuser.v94/ex3-10.xlsx"

out=mydata dbms=xlsx replace;
run;

 

title "Box Plot";
proc sgpanel data = mydata;
panelby _1985 _1996 _2002;
vbox year;

*I put year because thats how I think I would get the 3 seperate boxplots but variable is not valid since I cannot get the three columns to be taken as year;

run;

 

I have also included the dataset that I was given

Super User
Posts: 19,080

Re: box plots on same axis

Transpose your data so you can specify the CATEGORY=YEAR.

 

You can use PROC TRANSPOSE to transform your data.

http://documentation.sas.com/?docsetId=proc&docsetVersion=9.4&docsetTarget=n01rzqgzs8vq1bn10h1wtx914...

 

You don't need SGPANEL, unless you want it panelled. I'm unsure if you're looking for a single graph with three boxes or something else now. 

 


Steelz91 wrote:

*I put year because thats how I think I would get the 3 seperate boxplots but variable is not valid since I cannot get the three columns to be taken as year;

 

 


I think you're not understanding how the PANELBY is created, but I may also not be understanding what you want. Since this is a graph question, I'll move it to the graph forum. The SAS graph staff is great at answering questions.

 

New Contributor
Posts: 3

Re: box plots on same axis


Reeza wrote:

Transpose your data so you can specify the CATEGORY=YEAR.

 

You can use PROC TRANSPOSE to transform your data.

http://documentation.sas.com/?docsetId=proc&docsetVersion=9.4&docsetTarget=n01rzqgzs8vq1bn10h1wtx914...

 

You don't need SGPANEL, unless you want it panelled. I'm unsure if you're looking for a single graph with three boxes or something else now. 

 


Steelz91 wrote:

*I put year because thats how I think I would get the 3 seperate boxplots but variable is not valid since I cannot get the three columns to be taken as year;

 

 


I think you're not understanding how the PANELBY is created, but I may also not be understanding what you want. Since this is a graph question, I'll move it to the graph forum. The SAS graph staff is great at answering questions.

 


Okay thank you, yeah I want it all on a single graph. I kept googling how to do it and I kept getting the Panelby syntax popping up so I figured maybe they were using that and combining the graph. 

Super User
Posts: 19,080

Re: box plots on same axis

Check the link I included in my first post. It's probably almost exactly what you want.

Ask a Question
Discussion stats
  • 5 replies
  • 154 views
  • 0 likes
  • 2 in conversation