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-2024.png

 

Secure your spot at the must-attend AI and analytics event of 2024: SAS Innovate 2024! Get ready for a jam-packed agenda featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.

 

Register by March 1 to snag the Early Bird rate of just $695! Don't miss out on this exclusive offer. 

 

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.

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
  • 5 replies
  • 846 views
  • 3 likes
  • 3 in conversation