BookmarkSubscribeRSS Feed
LeniLesola
Fluorite | Level 6

Hey I would like to create a graph using the command:

 

PROC SGPLOT DATA = work.GruppierungAlter;
VBAR PHQg_gr / GROUP = OHIPg_gr ;
RUN;

 

I would like to divide each of the columns again into male and female gender or different age groups.

Can anyone help?

Thanks

7 REPLIES 7
PaigeMiller
Diamond | Level 26

If you already have a group variable, you can't further group within the bars on gender or age.

 

You could, I suppose, in the data set named work.GruppierungAlter, create a new variable which is the concatenation of OHIPg_gr and gender, or the concatenation of OHIPg_gr  and age, and then use these new variables as the GROUP= variable in PROC SGPLOT.

 

Alternatively, you could use PROC SGPANEL to put the different genders in side-by-side bar charts, or to put the different age groups in side-by-side bar charts.

--
Paige Miller
LeniLesola
Fluorite | Level 6
Thank you for your help.
I'm using now the command:
proc sgpanel data=work.GruppierungAlter;
panelby ci_sex;
vbar OHIPg_gr / response=PHQg stat=mean
transparency=0.3;
run;

but i would like to have something like this example but the columns should be divided into male and female or age groups.. Can you help?
(so here is a link, i would like to have it like in the picture but the columns divided by age/sex https://deref-web.de/mail/client/xPL0hDoPijU/dereferrer/?redirectUrl=https%3A%2F%2Fblogs.sas.com%2Fc...)
proc sgplot data=FreqOut;
vbar Origin / response=Percent group=Type groupdisplay=stack;
xaxis discreteorder=data;
yaxis grid values=(0 to 100 by 10) label="Percentage of Total with Group";
run;
PaigeMiller
Diamond | Level 26

VBAR in PROC SGPANEL allows you to have a GROUP variable which could be sex or anything else you want.

--
Paige Miller
ballardw
Super User

Perhaps you want an SGpanel with Panelby PHQg_gr , Vbar OHIPg_gr /group (sex/ age / other variable)

or make the original Group variable a PanelBy.

If you don't have many values for PHQg_gr you could force all the plot on a single row with the /rows=1 option in the Panelby statement. May have to play with some barwidth and other spacing options.

LeniLesola
Fluorite | Level 6
It doesn't work unfortunately.
If i try it with this step:
proc SGPLOT data = work.GruppierungAlter;
vbar OHIPg_gr/group = PHQg_gr;
run;
quit;

How is it possible to divide each columns in male/female?
PaigeMiller
Diamond | Level 26

Hard to say, as you didn't tell us what didn't work.

 

How is it possible to divide each columns in male/female?

 

As I said, PROC SGPANEL allows a GROUP= option

--
Paige Miller
ballardw
Super User

@LeniLesola wrote:
It doesn't work unfortunately.
If i try it with this step:
proc SGPLOT data = work.GruppierungAlter;
vbar OHIPg_gr/group = PHQg_gr;
run;
quit;

How is it possible to divide each columns in male/female?

Not at all related to what I suggested. I suggested Proc SGPANEL.

Something like:

proc sgpanel data = work.GruppierungAlter;
panelby OHIPg_gr;
vbar  PHQg_gr /group = sex;
run;
quit;

Maybe.

 

Without data we cannot test your code to make more targeted solutions.

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 1035 views
  • 6 likes
  • 3 in conversation