<?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 to display percentage for character strings in bar chart? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-display-percentage-for-character-strings-in-bar-chart/m-p/891190#M352083</link>
    <description>&lt;P&gt;Anytime you discuss percentages you always want to define which values are numerator/denominator of the value you want to display. I am not sure which you want and so it might be that additional manipulation of the data is actually needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However to change a plot from a frequency plot to percent may be as simple as:&lt;/P&gt;
&lt;PRE&gt;proc sgplot data=long;
	vbar sex / group=reason groupdisplay=cluster
                   stat=percent
                      ;
	xaxis label='Sexl';
run;&lt;/PRE&gt;
&lt;P&gt;to display the percent at the end of the bar add the DATALABEL option on the VBAR statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want the percents to be within the Group you might use:&lt;/P&gt;
&lt;PRE&gt;proc sgplot data=long  pctlevel=group;
	vbar sex / group=reason groupdisplay=cluster;
	xaxis label='Sexl';
run;&lt;/PRE&gt;
&lt;P&gt;If neither of those is what you expect then provide some details.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 25 Aug 2023 23:31:20 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-08-25T23:31:20Z</dc:date>
    <item>
      <title>How to display percentage for character strings in bar chart?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-display-percentage-for-character-strings-in-bar-chart/m-p/891188#M352082</link>
      <description>&lt;P&gt;I have a data looks like below:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;ID   sex        education        Reason1        Reason2           Reason3 
1   female         high           A                B                 C
2   male          middle          B                D                 E
3   female       college          A                B                 D&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;There are 6 reasons (A, B, C, D, E, F), and each person needs to select three out of the six. I want to create a bar chart to display three reasons for demographic groups. In order to make sure all three reason variables are displayed in the bar chart, I convert the data into long format, so all three reason variables were combined like below:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;ID     sex      education       reason
1    female       high             A
1    female       high             B
1    female       high             C
2    male         middle           B
2    male         middle           D
2    male         middle           E
3    female       college          A
3    female       college          B
3    female       college          D&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I used the code like below to generate the bar chart, so it displays the frequency of each reasons for different demographic groups:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sgplot data=long;
	vbar sex / group=reason groupdisplay=cluster;
	xaxis label='Sexl';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, since the group size is not balanced, I want to display percentage for each reason instead of frequency. But I am not sure how to do it, could anyone help me with it? Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2023 21:29:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-display-percentage-for-character-strings-in-bar-chart/m-p/891188#M352082</guid>
      <dc:creator>SAS-questioner</dc:creator>
      <dc:date>2023-08-25T21:29:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to display percentage for character strings in bar chart?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-display-percentage-for-character-strings-in-bar-chart/m-p/891190#M352083</link>
      <description>&lt;P&gt;Anytime you discuss percentages you always want to define which values are numerator/denominator of the value you want to display. I am not sure which you want and so it might be that additional manipulation of the data is actually needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However to change a plot from a frequency plot to percent may be as simple as:&lt;/P&gt;
&lt;PRE&gt;proc sgplot data=long;
	vbar sex / group=reason groupdisplay=cluster
                   stat=percent
                      ;
	xaxis label='Sexl';
run;&lt;/PRE&gt;
&lt;P&gt;to display the percent at the end of the bar add the DATALABEL option on the VBAR statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want the percents to be within the Group you might use:&lt;/P&gt;
&lt;PRE&gt;proc sgplot data=long  pctlevel=group;
	vbar sex / group=reason groupdisplay=cluster;
	xaxis label='Sexl';
run;&lt;/PRE&gt;
&lt;P&gt;If neither of those is what you expect then provide some details.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2023 23:31:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-display-percentage-for-character-strings-in-bar-chart/m-p/891190#M352083</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-08-25T23:31:20Z</dc:date>
    </item>
  </channel>
</rss>

