BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
James_Yu
Obsidian | Level 7

Hi everyone, 

I would like to create a vertical bar chart that looks like this:

James_Yu_0-1652952181222.png

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)

James_Yu_0-1652969163501.png

 

Could you any idea to create this chart 

Many thanks in advance

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

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;

View solution in original post

5 REPLIES 5
Ksharp
Super User
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;

Ksharp_0-1652957695854.png

 

James_Yu
Obsidian | Level 7

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 ?

 
 

James_Yu_2-1652969006463.png

 

DanH_sas
SAS Super FREQ

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;
James_Yu
Obsidian | Level 7
Thanks for the codes,
Your idea guide me a lot to modify my code
Ksharp
Super User
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;

Ksharp_0-1653051194653.png

 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 2207 views
  • 3 likes
  • 3 in conversation