BookmarkSubscribeRSS Feed
robertrao
Quartz | Level 8

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

16 REPLIES 16
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
robertrao
Quartz | Level 8

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

Reeza
Super User

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

robertrao
Quartz | Level 8

Thanks for the reply,

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

Thanks

Reeza
Super User

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

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

AncaTilea
Pyrite | Level 9

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;

robertrao
Quartz | Level 8

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

AncaTilea
Pyrite | Level 9

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

robertrao
Quartz | Level 8

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!!!

AncaTilea
Pyrite | Level 9

Right,

so you should sort by cancer, not by age.

you should sort by whatever your group variable is.

Anca.

robertrao
Quartz | Level 8

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

AncaTilea
Pyrite | Level 9

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

robertrao
Quartz | Level 8

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

AncaTilea
Pyrite | Level 9

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 16 replies
  • 1719 views
  • 0 likes
  • 4 in conversation