Help using Base SAS procedures

Box plot question

Reply
Super Contributor
Posts: 1,041

Box plot question

Hi ,

If we want a box plot for height and weight  using univariate

Do we need to do:

1) agegroup*height 

or

gender*height???????

Thanks

Trusted Advisor
Posts: 1,914

Re: Box plot question

Posted in reply to robertrao

You ask a question about height and weight, but then list possible answers that involve agegroup and height, or gender and height.

I'm confused.

Super Contributor
Posts: 1,041

Re: Box plot question

Posted in reply to PaigeMiller

Ok. I will make it little clear.

I have 3 yrs data and have height  weight age gender variables

for height as box plot what will be on x-axis and what would be on y-axis???

Thnks

Super User
Posts: 19,789

Re: Box plot question

Posted in reply to robertrao

A box plot by definition is for one variable to show the distribution. 

Plots can be shown horizontally or vertically, so the x/y can change. See the blog post below that describes box and whisker plots and how they look coming out of SAS EG.

How do you want to compare the distributions will define how you code it. EG Do you want to compare height and weight by sex for example and see if the distributions are different?

AnnMaria’s Blog

Super Contributor
Posts: 1,041

Re: Box plot question

Thanks for the reply,

If i wanted height and weight by gender then what would be the proc univariate code???

Thanks

Super User
Posts: 19,789

Re: Box plot question

Posted in reply to robertrao

I don't know how to do it in univariate.

There's a proc boxplot though, that has good examples in the documentation.

Super Contributor
Posts: 543

Re: Box plot question

Posted in reply to robertrao

Robert,

Is this what you'd like?.

proc sort data = sashelp.class out = foo;by sex;

proc boxplot data = foo;

    plot (weight height) * sex;

run;quit;

...or?

and there is this in UNIVARIATE:

proc univariate data = foo plots;

    var height weight;

        by sex;

run;

Super Contributor
Posts: 1,041

Re: Box plot question

Posted in reply to AncaTilea

Hi,

Thanks so much. I was expecting like the result of using thwe box plot procedure

Secondly, if i want to list the comorbities by age does the same hold good???

proc boxplot data = have1;

    plot (cancer AIDS TYPHOID) * age;

run;quit;

cancer AIDS and TYPHOID are different variables in the dataset

Super Contributor
Posts: 543

Re: Box plot question

Posted in reply to robertrao

So, let me see if I understand correctly.

You would like to plot distribution of Age by Cancer (yes/no)

So cancer is your x-axis, and age is your y-axis

thus

proc boxplot data = foo;

     plot age * cancer;

run;

Not the other way around.

So, the box plot will work for multiple plots creation for various Y axis values (age,height, weight), but not for various X-axis...

ummm,

so you can't have

proc boxplot data = foo;

     plot age * (cancer aids typhoid)

run;

You will need three plots statement:

proc sort data = sashelp.class out = foo;by sex name;

proc boxplot data = foo;

    plot height * sex;

    plot height * name;

run;quit;

.

Smiley Happy

Super Contributor
Posts: 1,041

Re: Box plot question

Posted in reply to AncaTilea

After sorting the TEST dataset i used the following code and it doesnt work for me???

proc boxplot data=test;

plot age*cancer/boxwidth=3 boxstyle=schematic haxis=axis1 clipfactor=4.5 clipsymbol  = dot

      cliplegpos  = top

      cliplegend  = '# Clipped Boxes'

      clipsubchar = '#';

inset nobs ;

insetgroup N mean min max Q3/header='Statistics' position=bottom cfillh=silver;

run;

ods pdf close;

I get an error saying that the values of the group variable CANCER are not sorted in the assending orderr!!!

Super Contributor
Posts: 543

Re: Box plot question

Posted in reply to robertrao

Right,

so you should sort by cancer, not by age.

you should sort by whatever your group variable is.

Anca.

Super Contributor
Posts: 1,041

Re: Box plot question

Posted in reply to AncaTilea

so always it is

plot yaxis*x-axis??????

and x axis is a grouping variable which needs to be sorted????

2)multiple plot statement means we get different outputs for each plot stmnt????

3)when do we use this king of grouping in the y-axis???

plot (weight height) * sex;

is it same as

plot (weight) * sex;

plot (height) * sex;

4) Also how can i get a box plot like below:

                  |

age           |

                  |

                  |

                  |

                   -----------------------------------------------

                        cancer           HIV             HTN...etc

Thanks

Super Contributor
Posts: 543

Re: Box plot question

Posted in reply to robertrao

Yes, always y*x

X-axis SHOULD be the grouping variable.

Multiple plot statements do give you multiple plots.

Yes, the (y1 y2 y3) * x is the same as plot y1*x

     plot y2*x...

Cheers.

Smiley Happy

Super Contributor
Posts: 1,041

Re: Box plot question

Posted in reply to AncaTilea

Hi Anca,

4) Also how can i get a box plot like below when Cancer HIV and HTN are different variables in the dataset:

i think it can be only acheived if all of these categories are under the same variable...

in my case it cant be acheived because a person can have a flag more than one category and so i cant acheive that??

is mu logic right????

                  |

age           |

                  |

                  |

                  |

                   -----------------------------------------------

                        cancer           HIV             HTN...etc

Super Contributor
Posts: 543

Re: Box plot question

Posted in reply to robertrao

To have the three comorbid conditions on the x-axis you'll have the re-arrange your data,

and create a group variable (for example)

say you have

id age cancer aids typhoid

1 23    0          0          0

2 87     1          0          0

becomes

id age grp_value grp_name

1   23  0          cancer

1 23    0           aids

1 23  0           typhoid

2 87     1     cancer

2 87 0      aids

2 87 0 typhoid

then you'd plot

proc boxplot;

plot age * grp_value =  grp_name;

run;

For example (bad example)

data foo;

    set sashelp.class;

    if substr(name,1,1) = "J" then grp = 1;

    else grp = 2;

run;

proc sort data = foo;by grp sex;

proc boxplot data = foo;

    plot height * sex = grp;

run;quit;

Ask a Question
Discussion stats
  • 16 replies
  • 510 views
  • 0 likes
  • 4 in conversation