Hi everyone,
I would like to create a vertical bar chart that looks like this:
In the chart, I would like to group 2 variables (Sex and Category) but the "Group" option in the Vbar statement only accepts 1 variable. I have tried to use sgpanel but I need 2 columns close together and I think I will use another variable (like age group) in the "panelby" statement to make comparison
The final chart should be like this (an example from an article)
Could you any idea to create this chart
Many thanks in advance
Building on @Ksharp's example, would this kind of display work for you?
ods html file="gridded.html";
ods layout gridded advance=bygroup rowgutter=0;
ods region;
ods graphics / width=100% height=150px;
proc sgpanel data=sashelp.heart noautolegend;
by chol_status;
panelby status/layout=columnlattice onepanel novarname HEADERBACKCOLOR=white noborder
NOHEADERBORDER COLHEADERPOS=bottom;
vbar sex/group=bp_status BARWIDTH=0.95;
colaxis display=(nolabel) offsetmin=0.4 offsetmax=0.4;
run;
ods layout end;
ods html close;
proc sgpanel data=sashelp.heart noautolegend;
panelby status/layout=columnlattice onepanel novarname HEADERBACKCOLOR=white noborder
NOHEADERBORDER COLHEADERPOS=bottom;
vbar sex/group=bp_status BARWIDTH=0.95;
colaxis display=(nolabel) offsetmin=0.4 offsetmax=0.4;
run;
Thanks for the code
But I think this only solves half of my problem. After that code, I could not find out how to add another variable into the chart
Let me take an example of the chart from an article. I think that would be complex but I need to add 3 grouping variables into my chart.
Could we do it on SAS ?
Building on @Ksharp's example, would this kind of display work for you?
ods html file="gridded.html";
ods layout gridded advance=bygroup rowgutter=0;
ods region;
ods graphics / width=100% height=150px;
proc sgpanel data=sashelp.heart noautolegend;
by chol_status;
panelby status/layout=columnlattice onepanel novarname HEADERBACKCOLOR=white noborder
NOHEADERBORDER COLHEADERPOS=bottom;
vbar sex/group=bp_status BARWIDTH=0.95;
colaxis display=(nolabel) offsetmin=0.4 offsetmax=0.4;
run;
ods layout end;
ods html close;
proc sgpanel data=sashelp.heart noautolegend;
panelby Smoking_Status bp_status/layout=lattice onepanel novarname HEADERBACKCOLOR=white noborder
NOHEADERBORDER COLHEADERPOS=bottom;
vbar sex/group=Weight_Status BARWIDTH=0.9;
colaxis display=(nolabel) offsetmin=0.4 offsetmax=0.4;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.