Help using Base SAS procedures

Creating a vbar comparing variables

Reply
N/A
Posts: 0

Creating a vbar comparing variables

I have a list of ages and blood pressures for 10000 people. How do I create a gchart bar chart to show average blood pressure for people in their 20s, 30s, 40s, 50, 60s, 70s 80s? I've gotten to:

proc gchart data= survey;
vbar age / midpoints = 20 to 80 by 10;
run;

which isn't all that close. I can't figure out how to include the average blood pressure (variable: sys) as well. Thanks in advance. Message was edited by: YaoPau
Super User
Posts: 10,023

Re: Creating a vbar comparing variables

Posted in reply to deleted_user
Hi.
Your vbar variable is numeric , so SAS will automatically compute midpoint of horizontal axis.
You need option ' discrete ' to fit the axis or change 'age' into character type.

[pre]
proc gchart data= sashelp.class;
vbar age / midpoints = 11 to 15 sumvar=height type=mean discrete;
run;
[/pre]


P.S. Actually If you post your question to the 'SAS graphic',There is a sas-man named Robort would solve it.


Ksharp

Message was edited by: Ksharp
Valued Guide
Posts: 634

Re: Creating a vbar comparing variables

Posted in reply to deleted_user
You are actually quite close, to incorporate KSharps answer (untested):
[pre]proc gchart data= survey;
vbar age / midpoints = 20 to 80 by 10
sumvar=pressure type=mean;
run;
[/pre]

Groups for your numeric variable can also be formed using a format. Using the DISCRETE option will give you one level per value for age.
Respected Advisor
Posts: 3,799

Re: Creating a vbar comparing variables

Posted in reply to deleted_user
This program indicates that the ages are rounded to the midpoint values, as the first two bar charts appear to be the same. I you want age ranges 20-29, 30-39 etc. you will need to create a format or a new variable as in AGEG2.



[pre]
proc plan seed=1245760598;
factors subj=10000 ordered age=1 of 65 sys=1 of 91;
output out=survey age nvals=(20 to 84) sys nvals=(50 to 140);
run;
quit;
data survey;
set survey;
ageg = round(age,10);
ageg2 = floor(age/10)*10;
run;
proc print data=_last_(obs=100);
run;

proc gchart data= survey;
Hbar age / midpoints = 20 to 80 by 10 sumvar=sys type=mean;
Hbar ageg / discrete sumvar=sys type=mean;
Hbar ageg2 / discrete sumvar=sys type=mean;
run;
quit;
[/pre]
Ask a Question
Discussion stats
  • 3 replies
  • 97 views
  • 0 likes
  • 4 in conversation