<?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 : how to add the total N of stacked plots in vbar label in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/Proc-SGplot-how-to-add-the-total-N-of-stacked-plots-in-vbar/m-p/869378#M23668</link>
    <description>&lt;P&gt;Use vbarparm statement to instead vbar, and use series statement to add data label.&lt;/P&gt;
&lt;PRE&gt;proc freq data=cars noprint;
  where origin eq 'Asia' and make in ('Toyota', 'Hyundai', 'Honda');
  tables make*type/out=cars_computed outpct;
run;

data cars_computed;
  set cars_computed;
  by make;

  pct_row=pct_row/100;
  dummy=1;
  if last.make then do;
    deno=round(count/pct_row);
    dlab=cats('N=',deno);
  end;
run;

proc sgplot data = cars_computed;
  vbarparm category=Make response=pct_row/group=type seglabel dataskin=pressed; 
  series x=Make y=dummy/datalabel=dlab datalabelpos=top lineattrs=(thickness=0) markerattrs=(size=0);
  xaxis discreteorder=data;
  yaxis label='Percent' offsetmax=0.05;
  format pct_row percent12.1;
run; &lt;/PRE&gt;
&lt;P&gt;The result:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 640px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/82637i703CBB4852AAC706/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 12 Apr 2023 08:31:31 GMT</pubDate>
    <dc:creator>whymath</dc:creator>
    <dc:date>2023-04-12T08:31:31Z</dc:date>
    <item>
      <title>Proc SGplot : how to add the total N of stacked plots in vbar label</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Proc-SGplot-how-to-add-the-total-N-of-stacked-plots-in-vbar/m-p/869216#M23667</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have stacked plots that need total N to be displayed in Vbar label (on top or the bottom of the bar). I've tried&amp;nbsp;&lt;STRONG&gt;xaxistable cat/ stat=freq label="N";&lt;/STRONG&gt;&amp;nbsp;statement in proc sgplot , but it is not giving Total N, instead the Group N stacked in the bar chart. Does anyone share the techniques that would do the task?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	data cars;
		set sashelp.cars;
		if type eq 'Hybrid' then cat=1;
		else if type eq 'Sedan' then cat=2;
		else if type eq 'Sports' then cat=3;
		else if type eq 'SUV' then cat=4;
		else if type eq 'Truck' then cat=5;
		if cat ne .;
	run; 

	proc sgplot data = cars pctlevel=group;
		where origin eq 'Asia' and make in ('Toyota', 'Hyundai', 'Honda');
		vbar make / stat=percent group= type seglabel dataskin=pressed; 
		xaxis discreteorder=data;
		yaxis label='Percent';
	run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Expected output is below,&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="With N= labels" style="width: 712px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/82534iB3C5DE68B0C35282/image-size/large?v=v2&amp;amp;px=999" role="button" title="cars.PNG" alt="With N= labels" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;With N= labels&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2023 21:30:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Proc-SGplot-how-to-add-the-total-N-of-stacked-plots-in-vbar/m-p/869216#M23667</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2023-04-11T21:30:51Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SGplot : how to add the total N of stacked plots in vbar label</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Proc-SGplot-how-to-add-the-total-N-of-stacked-plots-in-vbar/m-p/869378#M23668</link>
      <description>&lt;P&gt;Use vbarparm statement to instead vbar, and use series statement to add data label.&lt;/P&gt;
&lt;PRE&gt;proc freq data=cars noprint;
  where origin eq 'Asia' and make in ('Toyota', 'Hyundai', 'Honda');
  tables make*type/out=cars_computed outpct;
run;

data cars_computed;
  set cars_computed;
  by make;

  pct_row=pct_row/100;
  dummy=1;
  if last.make then do;
    deno=round(count/pct_row);
    dlab=cats('N=',deno);
  end;
run;

proc sgplot data = cars_computed;
  vbarparm category=Make response=pct_row/group=type seglabel dataskin=pressed; 
  series x=Make y=dummy/datalabel=dlab datalabelpos=top lineattrs=(thickness=0) markerattrs=(size=0);
  xaxis discreteorder=data;
  yaxis label='Percent' offsetmax=0.05;
  format pct_row percent12.1;
run; &lt;/PRE&gt;
&lt;P&gt;The result:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 640px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/82637i703CBB4852AAC706/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2023 08:31:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Proc-SGplot-how-to-add-the-total-N-of-stacked-plots-in-vbar/m-p/869378#M23668</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2023-04-12T08:31:31Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SGplot : how to add the total N of stacked plots in vbar label</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Proc-SGplot-how-to-add-the-total-N-of-stacked-plots-in-vbar/m-p/869431#M23669</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/270406"&gt;@whymath&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's awesome!&lt;/P&gt;
&lt;P&gt;Thank you for your help! I like the way totals and percent to be created in data step.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2023 15:57:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Proc-SGplot-how-to-add-the-total-N-of-stacked-plots-in-vbar/m-p/869431#M23669</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2023-04-12T15:57:24Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SGplot : how to add the total N of stacked plots in vbar label</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Proc-SGplot-how-to-add-the-total-N-of-stacked-plots-in-vbar/m-p/869439#M23670</link>
      <description>&lt;P&gt;I would suggest one modification to this solution: try using the TEXT plot instead of the SERIES plot. That way, you don't have to turn off the plot features just to get the labels.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Put this in place of the SERIES plot statement:&lt;/P&gt;
&lt;P&gt;text x=make y=dummy text=dlab / position=top;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps!&lt;/P&gt;
&lt;P&gt;Dan&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2023 16:56:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Proc-SGplot-how-to-add-the-total-N-of-stacked-plots-in-vbar/m-p/869439#M23670</guid>
      <dc:creator>DanH_sas</dc:creator>
      <dc:date>2023-04-12T16:56:39Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SGplot : how to add the total N of stacked plots in vbar label</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Proc-SGplot-how-to-add-the-total-N-of-stacked-plots-in-vbar/m-p/869500#M23671</link>
      <description>Good idea!</description>
      <pubDate>Thu, 13 Apr 2023 02:06:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Proc-SGplot-how-to-add-the-total-N-of-stacked-plots-in-vbar/m-p/869500#M23671</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2023-04-13T02:06:03Z</dc:date>
    </item>
  </channel>
</rss>

