<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Stacked bar chart comparing 2 groups over multiple variables in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/Stacked-bar-chart-comparing-2-groups-over-multiple-variables/m-p/927255#M24606</link>
    <description>&lt;P&gt;You need to change your data structure by PROC TRANSPOSE to get this kind of graph.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 call streaminit(123);
 do total_qual_care_score=0 to 8;
   do id=1 to 100;
   TM_non_ADRD_group=rand('bern',0.2);
   MA_non_ADRD_group=rand('bern',0.8);
   output;
   end;
 end;
 run;
proc transpose data=have out=temp;
by total_qual_care_score id;
var TM_non_ADRD_group MA_non_ADRD_group;
run;
proc summary data=temp nway;
class total_qual_care_score _NAME_;
var col1;
output out=temp2 mean=mean lclm=lclm uclm=uclm;
run;
data want;
 set temp2;
 by total_qual_care_score ;
 if first.total_qual_care_score then call missing(cum_mean,cum_lclm,cum_uclm);
 cum_mean+mean;
 _lclm=mean-lclm;cum_lclm=cum_mean-_lclm;
 _uclm=uclm-mean;cum_uclm=cum_mean+_uclm;
run;
 
 
PROC SGPLOT data=want;
vbarparm category=total_qual_care_score response=mean/ group=_NAME_ name='x' ;
scatter x=total_qual_care_score y=cum_mean/markerattrs=(size=0) yerrorlower=cum_lclm yerrorupper=cum_uclm;
xaxis label='Total Quality of Care Score';
yaxis label='Proportion satisfied';
keylegend 'x'/title='';
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1715046744069.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96207iD0814ABB24C72979/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1715046744069.png" alt="Ksharp_0-1715046744069.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 07 May 2024 01:52:32 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2024-05-07T01:52:32Z</dc:date>
    <item>
      <title>Stacked bar chart comparing 2 groups over multiple variables</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Stacked-bar-chart-comparing-2-groups-over-multiple-variables/m-p/927228#M24601</link>
      <description>&lt;P&gt;I trying to create a stacked bar chart comparing MA and TM groups on 8 different binary variables (I've only shown 2 here for simplicity) and 1 discrete (0-8) continuous variable.&amp;nbsp; I've created a chart for the continuous variable, and it's pretty close to what I need. Here's what I need to change:&lt;/P&gt;
&lt;P&gt;1) The bars are the same color, so it's not clear which group is higher/lower.&lt;/P&gt;
&lt;P&gt;2) I'd like to add the name of the group that goes to each color.&lt;/P&gt;
&lt;P&gt;3) I need to replace the variable name total_qual_care_score with a label such as "Total Quality of Care Score".&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SGPlot4 total_qual_care.png" style="width: 640px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96202iB7441DF74C9769D8/image-size/large?v=v2&amp;amp;px=999" role="button" title="SGPlot4 total_qual_care.png" alt="SGPlot4 total_qual_care.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the binary variables, I'd like to have both in a single chart. I haven't been able to create an example chart, but imagine that only the 0 and 1 bars exist. And instead of 0 and 1, the columns represent ACC_HCTROUBL_r and ACC_HCDELAY_r (with the labels "Trouble getting care" and "Delay in getting care", respectively).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's my current code with sample data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines dsd dlm=',' truncover;
  input Obs cohort_flag MA_non_ADRD_group TM_non_ADRD_group	total_qual_care_score ACC_HCTROUBL_r ACC_HCDELAY_r;
datalines;
1,1,1,0,7,1,0
2,1,0,1,7,0,1
3,1,0,1,7,1,0
4,1,0,0,1,0,1
5,1,0,0,8,0,1
6,1,0,1,7,0,1
7,1,0,1,3,1,0
8,1,0,1,7,0,1
9,1,0,1,8,1,0
10,1,1,0,5,0,1
11,1,1,0,8,0,0
12,1,0,1,8,1,1
13,1,1,0,8,0,1
14,0,,,7,0,1
15,1,0,1,8,0,1
16,1,0,1,8,0,0
17,1,1,0,8,0,1
18,1,0,0,7,0,0
19,1,1,0,8,1,0
20,1,0,1,6,0,1
21,1,0,1,7,1,1
22,1,1,0,7,0,0
23,1,0,1,5,1,0
24,1,0,1,8,0,1
25,1,0,1,8,0,1
; RUN;

title1 "Section 1.2 -- Fig1 Unadj rates quality care TM vs MA without ADRD";
title2 "Version &amp;amp;version.";
PROC MEANS data=have mean n lclm uclm stackods;
	class total_qual_care_score;
	var TM_non_ADRD_group MA_non_ADRD_group;
 ods output summary=temp.TM_MA_groupMean;
 	WHERE cohort_flag = 1 AND (TM_non_ADRD_group = 1 OR MA_non_ADRD_group = 1);
 RUN;
 
 
PROC SGPLOT data=temp.TM_MA_groupMean;
 vbarparm category=/*variable*/ total_qual_care_score response=mean /
    limitlower=lclm
    limitupper=uclm;
    label mean="Proportion satisfied";
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 May 2024 20:31:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Stacked-bar-chart-comparing-2-groups-over-multiple-variables/m-p/927228#M24601</guid>
      <dc:creator>Wolverine</dc:creator>
      <dc:date>2024-05-06T20:31:42Z</dc:date>
    </item>
    <item>
      <title>Re: Stacked bar chart comparing 2 groups over multiple variables</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Stacked-bar-chart-comparing-2-groups-over-multiple-variables/m-p/927229#M24602</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;UL class="lia-list-style-type-square"&gt;
&lt;LI&gt;&lt;A href="https://support.sas.com/sassamples/graphgallery/PROC_SGPLOT.html" target="_blank"&gt;https://support.sas.com/sassamples/graphgallery/PROC_SGPLOT.html&lt;/A&gt;&lt;BR /&gt;Scroll down to:&lt;BR /&gt;&lt;SPAN&gt;Sample 55866 - Use the SEGLABEL option to label bar segments in a bar chart&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://support.sas.com/sassamples/graphgallery/PROC_GCHART_Graph_Types_Charts_Bar.html" target="_blank"&gt;https://support.sas.com/sassamples/graphgallery/PROC_GCHART_Graph_Types_Charts_Bar.html&lt;/A&gt;&lt;BR /&gt;Scroll down to:&amp;nbsp;&lt;BR /&gt;&lt;SPAN&gt;Sample 48451 - Center the subgroup labels in a horizontal bar chart created with PROC GCHART&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT size="4"&gt;&lt;A href="https://support.sas.com/kb/24/880.html" target="_blank"&gt;https://support.sas.com/kb/24/880.html&lt;/A&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="4"&gt;Sample&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;I&gt;24880:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/I&gt;Reorder the subgroups in a stacked bar chart produced with PROC GCHART&lt;/FONT&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2024 20:46:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Stacked-bar-chart-comparing-2-groups-over-multiple-variables/m-p/927229#M24602</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2024-05-06T20:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: Stacked bar chart comparing 2 groups over multiple variables</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Stacked-bar-chart-comparing-2-groups-over-multiple-variables/m-p/927230#M24603</link>
      <description>&lt;PRE&gt;stacked bar chart in SAS site:blogs.sas.com&lt;/PRE&gt;
&lt;PRE&gt;stacked bar chart in SAS site:support.sas.com&lt;/PRE&gt;
&lt;P&gt;Google Search.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2024 20:49:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Stacked-bar-chart-comparing-2-groups-over-multiple-variables/m-p/927230#M24603</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2024-05-06T20:49:12Z</dc:date>
    </item>
    <item>
      <title>Re: Stacked bar chart comparing 2 groups over multiple variables</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Stacked-bar-chart-comparing-2-groups-over-multiple-variables/m-p/927232#M24604</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SGPLOT data=TM_MA_groupMean;
    vbarparm category=total_qual_care_score response=mean / group=variable groupdisplay=cluster
    limitlower=lclm limitupper=uclm;
    yaxis label="Proportion satisfied";
    xaxis label="Total Quality of Care Score";
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 May 2024 20:55:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Stacked-bar-chart-comparing-2-groups-over-multiple-variables/m-p/927232#M24604</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-05-06T20:55:44Z</dc:date>
    </item>
    <item>
      <title>Re: Stacked bar chart comparing 2 groups over multiple variables</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Stacked-bar-chart-comparing-2-groups-over-multiple-variables/m-p/927235#M24605</link>
      <description>&lt;P&gt;The general basic approach to differentiating bits of a graph based on the value of a variable is to use the Group=option. Which means this is where I would start:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;PROC SGPLOT data=work.TM_MA_groupMean;
 vbarparm category=/*variable*/ total_qual_care_score response=mean /
    limitlower=lclm
    limitupper=uclm;
    label mean="Proportion satisfied"
    group=  variable
    ;
RUN;&lt;/PRE&gt;
&lt;P&gt;However the size of&amp;nbsp; your example data set is so small that the procedure complains that the data may not work for the VBARPARM.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;LABEL your variable where you want the text instead of the name to appear.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the question about your "binary" variable actually boils down to "How do I get a value of 1 to display&amp;nbsp; "xxxx" and 0 to display "yyyy" text" then the question is usually a format.&lt;/P&gt;
&lt;P&gt;You don't provide anywhere near enough detail to tell what sort of graph but here is a small example using the binary variable in two roles in a bar.&lt;/P&gt;
&lt;PRE&gt;data example;
   set sashelp.class;
   /* create a binary 1/0 coded variable*/
   bin= sex='F';
run;


proc format library=work;
value bin
0= 'The text for 0'
1= 'The text for 1'
;
run;

proc sgplot data=example;
   vbar age/ response=height group=bin;
   format bin bin. ;
   label bin='The text I want for a label';
run;

proc sgplot data=example;
   vbar bin / response=height group=age;
   label bin='The text I want for a label';
   format bin bin. ;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2024 21:09:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Stacked-bar-chart-comparing-2-groups-over-multiple-variables/m-p/927235#M24605</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-05-06T21:09:47Z</dc:date>
    </item>
    <item>
      <title>Re: Stacked bar chart comparing 2 groups over multiple variables</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Stacked-bar-chart-comparing-2-groups-over-multiple-variables/m-p/927255#M24606</link>
      <description>&lt;P&gt;You need to change your data structure by PROC TRANSPOSE to get this kind of graph.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 call streaminit(123);
 do total_qual_care_score=0 to 8;
   do id=1 to 100;
   TM_non_ADRD_group=rand('bern',0.2);
   MA_non_ADRD_group=rand('bern',0.8);
   output;
   end;
 end;
 run;
proc transpose data=have out=temp;
by total_qual_care_score id;
var TM_non_ADRD_group MA_non_ADRD_group;
run;
proc summary data=temp nway;
class total_qual_care_score _NAME_;
var col1;
output out=temp2 mean=mean lclm=lclm uclm=uclm;
run;
data want;
 set temp2;
 by total_qual_care_score ;
 if first.total_qual_care_score then call missing(cum_mean,cum_lclm,cum_uclm);
 cum_mean+mean;
 _lclm=mean-lclm;cum_lclm=cum_mean-_lclm;
 _uclm=uclm-mean;cum_uclm=cum_mean+_uclm;
run;
 
 
PROC SGPLOT data=want;
vbarparm category=total_qual_care_score response=mean/ group=_NAME_ name='x' ;
scatter x=total_qual_care_score y=cum_mean/markerattrs=(size=0) yerrorlower=cum_lclm yerrorupper=cum_uclm;
xaxis label='Total Quality of Care Score';
yaxis label='Proportion satisfied';
keylegend 'x'/title='';
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1715046744069.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96207iD0814ABB24C72979/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1715046744069.png" alt="Ksharp_0-1715046744069.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2024 01:52:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Stacked-bar-chart-comparing-2-groups-over-multiple-variables/m-p/927255#M24606</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-05-07T01:52:32Z</dc:date>
    </item>
  </channel>
</rss>

