<?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: How do I label a stacked bar graph using HBARPARM with percent rather than count? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-label-a-stacked-bar-graph-using-HBARPARM-with-percent/m-p/818568#M323108</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data path_resistance;
	infile datalines delimiter = ',';
	input pathGroup :$40. pathResistant $ resCount resPct;
	format resPct percent.;
	datalines;
Pathogen A,No,170,.98
Pathogen A,Yes,3,.2
Pathogen B,No,100,.86
Pathogen B,Yes,6,.14
Pathogen C,No,53,.65
Pathogen C,Yes,28,.35
;
run;
data have;
 set path_resistance;
 by pathGroup;
 if first.pathGroup then cum=0;
 cum+resCount;
 p=cum-resCount/2;
run;

proc sgplot data = have;
	yaxis display = (nolabel) valueattrs = (color=black size=12pt);
	xaxis grid min=0 label="Number of infections" ;
	hbarparm category = pathGroup response = resCount /group = pathResistant;
   text x=p y=pathGroup text=resPct /strip CONTRIBUTEOFFSETS=none;
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-1655384948715.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72365i20E0AA4357A2FDF9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1655384948715.png" alt="Ksharp_0-1655384948715.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 16 Jun 2022 13:09:23 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2022-06-16T13:09:23Z</dc:date>
    <item>
      <title>How do I label a stacked bar graph using HBARPARM with percent rather than count?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-label-a-stacked-bar-graph-using-HBARPARM-with-percent/m-p/818487#M323071</link>
      <description>&lt;P&gt;Hello! I have a stacked bar graph created using HBARPARM and am trying to have the segment labels show the percentage, not the count. Is there a way to do that?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code is:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sgplot data = path_resistance;
	yaxis display = (nolabel) valueattrs = (color=black size=12pt);
	xaxis grid min=0 label="Number of infections" ;
	hbarparm category = pathGroup response = resCount / 
		group = pathResistant
		seglabel;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mksredl_0-1655327153016.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72356i22512F3C6CD18B49/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mksredl_0-1655327153016.png" alt="mksredl_0-1655327153016.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a column with the percentages (resPct). The structure of my data is:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data path_resistance;
	infile datalines delimiter = ',';
	input pathGroup pathResistant resCount resPct;
	datalines;
Pathogen A,No,170,98
Pathogen A,Yes,3,2
Pathogen B,No,100,86
Pathogen B,Yes,6,14
Pathogen C,No,53,65
Pathogen C,Yes,28,35
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you for the help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 21:12:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-label-a-stacked-bar-graph-using-HBARPARM-with-percent/m-p/818487#M323071</guid>
      <dc:creator>mksredl</dc:creator>
      <dc:date>2022-06-15T21:12:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do I label a stacked bar graph using HBARPARM with percent rather than count?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-label-a-stacked-bar-graph-using-HBARPARM-with-percent/m-p/818499#M323078</link>
      <description>&lt;P&gt;Use Respct as the Response variable is one way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or option Datalabel=respct on the hbarparm statement&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2022 00:21:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-label-a-stacked-bar-graph-using-HBARPARM-with-percent/m-p/818499#M323078</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-06-16T00:21:43Z</dc:date>
    </item>
    <item>
      <title>Re: How do I label a stacked bar graph using HBARPARM with percent rather than count?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-label-a-stacked-bar-graph-using-HBARPARM-with-percent/m-p/818568#M323108</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data path_resistance;
	infile datalines delimiter = ',';
	input pathGroup :$40. pathResistant $ resCount resPct;
	format resPct percent.;
	datalines;
Pathogen A,No,170,.98
Pathogen A,Yes,3,.2
Pathogen B,No,100,.86
Pathogen B,Yes,6,.14
Pathogen C,No,53,.65
Pathogen C,Yes,28,.35
;
run;
data have;
 set path_resistance;
 by pathGroup;
 if first.pathGroup then cum=0;
 cum+resCount;
 p=cum-resCount/2;
run;

proc sgplot data = have;
	yaxis display = (nolabel) valueattrs = (color=black size=12pt);
	xaxis grid min=0 label="Number of infections" ;
	hbarparm category = pathGroup response = resCount /group = pathResistant;
   text x=p y=pathGroup text=resPct /strip CONTRIBUTEOFFSETS=none;
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-1655384948715.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72365i20E0AA4357A2FDF9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1655384948715.png" alt="Ksharp_0-1655384948715.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2022 13:09:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-label-a-stacked-bar-graph-using-HBARPARM-with-percent/m-p/818568#M323108</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-06-16T13:09:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do I label a stacked bar graph using HBARPARM with percent rather than count?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-label-a-stacked-bar-graph-using-HBARPARM-with-percent/m-p/818574#M323110</link>
      <description>Perfect, thank you so much!</description>
      <pubDate>Thu, 16 Jun 2022 13:34:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-label-a-stacked-bar-graph-using-HBARPARM-with-percent/m-p/818574#M323110</guid>
      <dc:creator>mksredl</dc:creator>
      <dc:date>2022-06-16T13:34:29Z</dc:date>
    </item>
    <item>
      <title>Re: How do I label a stacked bar graph using HBARPARM with percent rather than count?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-label-a-stacked-bar-graph-using-HBARPARM-with-percent/m-p/818891#M323259</link>
      <description>&lt;P&gt;This solution worked great, thank you! Follow up question: is there a way to prevent the labels from overlapping when the bar is very small, such as in the last bar below?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mksredl_0-1655488800941.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72395iA1FCFD4F21C0BC91/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mksredl_0-1655488800941.png" alt="mksredl_0-1655488800941.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jun 2022 18:00:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-label-a-stacked-bar-graph-using-HBARPARM-with-percent/m-p/818891#M323259</guid>
      <dc:creator>mksredl</dc:creator>
      <dc:date>2022-06-17T18:00:20Z</dc:date>
    </item>
    <item>
      <title>Re: How do I label a stacked bar graph using HBARPARM with percent rather than count?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-label-a-stacked-bar-graph-using-HBARPARM-with-percent/m-p/818961#M323287</link>
      <description>&lt;P&gt;You need change the position of text according to your data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data path_resistance;
	infile datalines delimiter = ',';
	input pathGroup :$40. pathResistant $  resCount resPct;
	format resPct percent8.0;
	datalines;
Pathogen A,No,170,.98
Pathogen A,Yes,3,.02
Pathogen B,No,100,.86
Pathogen B,Yes,6,.14
Pathogen C,No,4,.60
Pathogen C,Yes,2,.40
;
run;

data have;
 set path_resistance;
 by pathGroup;
 if first.pathGroup then cum=0;
 cum+resCount;
 p=cum-resCount/2;
run;
data have2;
 set have;
 if pathGroup=lag(pathGroup) and dif(p)&amp;lt;10 then p=p+10;  *Change it according to your data.;
run;


proc sgplot data = have2;
	yaxis display = (nolabel) valueattrs = (color=black size=12pt);
	xaxis grid min=0 label="Number of infections" ;
	hbarparm category = pathGroup response = resCount /group = pathResistant;
	scatter x=p y=pathGroup /markerchar=resPct;
run;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1655545056309.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72408iA4D8908F5C3C79D5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1655545056309.png" alt="Ksharp_0-1655545056309.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Jun 2022 09:37:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-label-a-stacked-bar-graph-using-HBARPARM-with-percent/m-p/818961#M323287</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-06-18T09:37:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do I label a stacked bar graph using HBARPARM with percent rather than count?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-label-a-stacked-bar-graph-using-HBARPARM-with-percent/m-p/819129#M323350</link>
      <description>Thank you so much!</description>
      <pubDate>Mon, 20 Jun 2022 13:01:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-label-a-stacked-bar-graph-using-HBARPARM-with-percent/m-p/819129#M323350</guid>
      <dc:creator>mksredl</dc:creator>
      <dc:date>2022-06-20T13:01:18Z</dc:date>
    </item>
  </channel>
</rss>

