BookmarkSubscribeRSS Feed
Steelz91
Calcite | Level 5

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. 

 

5 REPLIES 5
Reeza
Super User

 

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. 

 


 

Steelz91
Calcite | Level 5

@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

Reeza
Super User

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.

 

Steelz91
Calcite | Level 5

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

Reeza
Super User

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 2077 views
  • 0 likes
  • 2 in conversation