<?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: Proc SGPLOT stacked bar graph with percents in bar in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-SGPLOT-stacked-bar-graph-with-percents-in-bar/m-p/706441#M216817</link>
    <description>&lt;P&gt;Remove the&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;  	vbar c_sx_technique / group=ratecurrent_level_func stat=freq;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Run this code and see the difference between the two statistic and one statistic versions:&lt;/P&gt;
&lt;PRE&gt;proc sgplot data=sashelp.class;
    title "Two Vbar statistics";
      vbar sex /group=age stat=freq ;
      vbar sex /group=age stat=percent seglabel;
run;

proc sgplot data=sashelp.class;
    title "One Vbar statistic";
      vbar sex /group=age stat=percent seglabel;
run;
&lt;/PRE&gt;
&lt;P&gt;If you look closely at the two statistic version and count the number of segments in each you will note that there is a big difference in the number of segments displayed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Quick: what is the decimal value of 15%?&lt;/P&gt;
&lt;P&gt;If you remember that is 0.15 then you can tell what happens when combined with a frequency bar: ALL the percents are less than 1 and the size is so small there is no room by default for the text to display. If you make the graph large enough you then may have room enough for text to display for some values:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ods graphics / height=20in;

proc sgplot data=sashelp.class;
    title "Two Vbar statistics";
      vbar sex /group=age stat=freq ;
      vbar sex /group=age stat=percent seglabel;
run;

ods graphics / reset=all;&lt;/PRE&gt;
&lt;P&gt;But stacking freq and percent on a single bar makes no sense any way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 16 Dec 2020 20:42:22 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-12-16T20:42:22Z</dc:date>
    <item>
      <title>Proc SGPLOT stacked bar graph with percents in bar</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SGPLOT-stacked-bar-graph-with-percents-in-bar/m-p/706109#M216696</link>
      <description>&lt;P&gt;Using SAS9.4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following code:&lt;/P&gt;
&lt;P&gt;proc sgplot data= peroneal.labeled pctlevel=graph;&lt;BR /&gt;styleattrs datacolors=(red blue green) ;&lt;BR /&gt;title 'Current Level of Function';&lt;BR /&gt;title2 'P=0.914';&lt;BR /&gt;vbar c_sx_technique / group=ratecurrent_level_func stat=freq;&lt;BR /&gt;vbar c_sx_technique / group=ratecurrent_level_func stat=percent_func datalabel;&lt;BR /&gt;xaxis display=(nolabel);&lt;BR /&gt;yaxis grid label='Frequency' values=(0 5 10 15 20 25 30 35 40);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to modify this code so the percent (created variable percent_func) within each stacked bar graph will be displayed on the bar? Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 15 Dec 2020 20:18:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SGPLOT-stacked-bar-graph-with-percents-in-bar/m-p/706109#M216696</guid>
      <dc:creator>GS2</dc:creator>
      <dc:date>2020-12-15T20:18:56Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SGPLOT stacked bar graph with percents in bar</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SGPLOT-stacked-bar-graph-with-percents-in-bar/m-p/706110#M216697</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194348"&gt;@GS2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Using SAS9.4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following code:&lt;/P&gt;
&lt;P&gt;proc sgplot data= peroneal.labeled pctlevel=graph;&lt;BR /&gt;styleattrs datacolors=(red blue green) ;&lt;BR /&gt;title 'Current Level of Function';&lt;BR /&gt;title2 'P=0.914';&lt;BR /&gt;vbar c_sx_technique / group=ratecurrent_level_func stat=freq;&lt;BR /&gt;vbar c_sx_technique / group=ratecurrent_level_func stat=percent_func datalabel;&lt;BR /&gt;xaxis display=(nolabel);&lt;BR /&gt;yaxis grid label='Frequency' values=(0 5 10 15 20 25 30 35 40);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to modify this code so the percent (created variable percent_func) within each stacked bar graph will be displayed on the bar? Thank you&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You might be looking for the SEGLABEL option for the vbar to label segments.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Dec 2020 20:23:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SGPLOT-stacked-bar-graph-with-percents-in-bar/m-p/706110#M216697</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-12-15T20:23:19Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SGPLOT stacked bar graph with percents in bar</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SGPLOT-stacked-bar-graph-with-percents-in-bar/m-p/706137#M216704</link>
      <description>&lt;P&gt;Hi GS2,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I might try these options:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATALABEL = COLPercent;&lt;BR /&gt;FORMAT COLPercent n.w; (to format as necessary)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The COLPercent option should label each column with the percent, no need to create a new variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Dec 2020 22:11:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SGPLOT-stacked-bar-graph-with-percents-in-bar/m-p/706137#M216704</guid>
      <dc:creator>anle2079</dc:creator>
      <dc:date>2020-12-15T22:11:41Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SGPLOT stacked bar graph with percents in bar</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SGPLOT-stacked-bar-graph-with-percents-in-bar/m-p/706297#M216766</link>
      <description>I tried this and got an error saying to use "pct" or "percent" and neither produced the output I am looking for. Thank you</description>
      <pubDate>Wed, 16 Dec 2020 13:39:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SGPLOT-stacked-bar-graph-with-percents-in-bar/m-p/706297#M216766</guid>
      <dc:creator>GS2</dc:creator>
      <dc:date>2020-12-16T13:39:55Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SGPLOT stacked bar graph with percents in bar</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SGPLOT-stacked-bar-graph-with-percents-in-bar/m-p/706383#M216808</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194348"&gt;@GS2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I tried this and got an error saying to use "pct" or "percent" and neither produced the output I am looking for. Thank you&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;When you get errors then best practice on this forum is to go to your log, copy the entire procedure code with all the notes, warning or errors and then on the forum open a text box using the &amp;lt;/&amp;gt; icon and paste the log text. The text box will preserve formatting of any diagnostic characters that SAS provides while the main message windows will reformat the text, sometimes resulting in very hard to read log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does this show something close to what you are looking for in terms of the percents on the bar:&lt;/P&gt;
&lt;PRE&gt;proc sgplot data=sashelp.class;
   vbar sex /group=age stat=percent seglabel;
run;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SGPlot.png" style="width: 640px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/52690i4022D8DB20C8E387/image-size/large?v=v2&amp;amp;px=999" role="button" title="SGPlot.png" alt="SGPlot.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2020 17:36:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SGPLOT-stacked-bar-graph-with-percents-in-bar/m-p/706383#M216808</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-12-16T17:36:13Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SGPLOT stacked bar graph with percents in bar</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SGPLOT-stacked-bar-graph-with-percents-in-bar/m-p/706398#M216810</link>
      <description>Yes, that is exactly how I would like to see it.</description>
      <pubDate>Wed, 16 Dec 2020 18:21:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SGPLOT-stacked-bar-graph-with-percents-in-bar/m-p/706398#M216810</guid>
      <dc:creator>GS2</dc:creator>
      <dc:date>2020-12-16T18:21:42Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SGPLOT stacked bar graph with percents in bar</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SGPLOT-stacked-bar-graph-with-percents-in-bar/m-p/706424#M216812</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194348"&gt;@GS2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Yes, that is exactly how I would like to see it.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your turn.&lt;/P&gt;
&lt;P&gt;Show us the code with SEGLABEL from your log that throws the errors.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2020 19:38:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SGPLOT-stacked-bar-graph-with-percents-in-bar/m-p/706424#M216812</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-12-16T19:38:13Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SGPLOT stacked bar graph with percents in bar</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SGPLOT-stacked-bar-graph-with-percents-in-bar/m-p/706425#M216813</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sgplot data= peroneal.labeled pctlevel=graph;
  	styleattrs datacolors=(red blue green) ;
  	title 'Current Level of Function';
  	title2 'P=0.914';
  	vbar c_sx_technique / group=ratecurrent_level_func stat=freq;
	vbar c_sx_technique / group=ratecurrent_level_func stat=percent seglabel;
	xaxis display=(nolabel);
 	yaxis grid label='Frequency' values=(0 5 10 15 20 25 30 35 40);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;146  proc sgplot data= peroneal.labeled pctlevel=graph;
147      styleattrs datacolors=(red blue green) ;
148      title 'Current Level of Function';
149      title2 'P=0.914';
150      vbar c_sx_technique / group=ratecurrent_level_func stat=freq;
151      vbar c_sx_technique / group=ratecurrent_level_func stat=percent seglabel;
152      xaxis display=(nolabel);
153      yaxis grid label='Frequency' values=(0 5 10 15 20 25 30 35 40);
154  run;

NOTE: PROCEDURE SGPLOT used (Total process time):
      real time           0.27 seconds
      cpu time            0.06 seconds

NOTE: There were 51 observations read from the data set PERONEAL.LABELED.


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I do not get an error when submitting the code but the percents do not show on the graph either&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2020 19:48:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SGPLOT-stacked-bar-graph-with-percents-in-bar/m-p/706425#M216813</guid>
      <dc:creator>GS2</dc:creator>
      <dc:date>2020-12-16T19:48:02Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SGPLOT stacked bar graph with percents in bar</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SGPLOT-stacked-bar-graph-with-percents-in-bar/m-p/706441#M216817</link>
      <description>&lt;P&gt;Remove the&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;  	vbar c_sx_technique / group=ratecurrent_level_func stat=freq;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Run this code and see the difference between the two statistic and one statistic versions:&lt;/P&gt;
&lt;PRE&gt;proc sgplot data=sashelp.class;
    title "Two Vbar statistics";
      vbar sex /group=age stat=freq ;
      vbar sex /group=age stat=percent seglabel;
run;

proc sgplot data=sashelp.class;
    title "One Vbar statistic";
      vbar sex /group=age stat=percent seglabel;
run;
&lt;/PRE&gt;
&lt;P&gt;If you look closely at the two statistic version and count the number of segments in each you will note that there is a big difference in the number of segments displayed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Quick: what is the decimal value of 15%?&lt;/P&gt;
&lt;P&gt;If you remember that is 0.15 then you can tell what happens when combined with a frequency bar: ALL the percents are less than 1 and the size is so small there is no room by default for the text to display. If you make the graph large enough you then may have room enough for text to display for some values:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ods graphics / height=20in;

proc sgplot data=sashelp.class;
    title "Two Vbar statistics";
      vbar sex /group=age stat=freq ;
      vbar sex /group=age stat=percent seglabel;
run;

ods graphics / reset=all;&lt;/PRE&gt;
&lt;P&gt;But stacking freq and percent on a single bar makes no sense any way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2020 20:42:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SGPLOT-stacked-bar-graph-with-percents-in-bar/m-p/706441#M216817</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-12-16T20:42:22Z</dc:date>
    </item>
  </channel>
</rss>

