<?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 How to get a horizontal stacked bar chart in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-a-horizontal-stacked-bar-chart/m-p/978539#M378622</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I'm trying to create a horizontal stacked bar chart to eventually export into Excel. I have my data but I can't get the chart working.&amp;nbsp; Here's what I have so far :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;data new;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; input lead $ north south east west;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; datalines;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; Joe 29 5 1 3&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; Suzie 4 6 8 19&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; Fred 109 8 2 36&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; Chris 235 48 29 54&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; ;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;proc sgplot data=new pctlevel=group;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; hbar lead /&amp;nbsp; stat=percent;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Here's the output I want with the colors to always be set to those colors.&lt;/DIV&gt;
&lt;DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASGeek_0-1762551432163.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/111210i622B2A61B3B19B67/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASGeek_0-1762551432163.png" alt="SASGeek_0-1762551432163.png" /&gt;&lt;/span&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Thank you&lt;/DIV&gt;</description>
    <pubDate>Fri, 07 Nov 2025 21:37:45 GMT</pubDate>
    <dc:creator>SASGeek</dc:creator>
    <dc:date>2025-11-07T21:37:45Z</dc:date>
    <item>
      <title>How to get a horizontal stacked bar chart</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-a-horizontal-stacked-bar-chart/m-p/978539#M378622</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I'm trying to create a horizontal stacked bar chart to eventually export into Excel. I have my data but I can't get the chart working.&amp;nbsp; Here's what I have so far :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;data new;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; input lead $ north south east west;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; datalines;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; Joe 29 5 1 3&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; Suzie 4 6 8 19&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; Fred 109 8 2 36&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; Chris 235 48 29 54&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; ;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;proc sgplot data=new pctlevel=group;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; hbar lead /&amp;nbsp; stat=percent;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Here's the output I want with the colors to always be set to those colors.&lt;/DIV&gt;
&lt;DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASGeek_0-1762551432163.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/111210i622B2A61B3B19B67/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASGeek_0-1762551432163.png" alt="SASGeek_0-1762551432163.png" /&gt;&lt;/span&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Thank you&lt;/DIV&gt;</description>
      <pubDate>Fri, 07 Nov 2025 21:37:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-a-horizontal-stacked-bar-chart/m-p/978539#M378622</guid>
      <dc:creator>SASGeek</dc:creator>
      <dc:date>2025-11-07T21:37:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a horizontal stacked bar chart</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-a-horizontal-stacked-bar-chart/m-p/978542#M378623</link>
      <description>&lt;P&gt;To get the 100% stacked bar chart, follow the article at&amp;nbsp; &lt;A href="https://blogs.sas.com/content/iml/2014/04/08/construct-a-stacked-bar-chart-in-sas-where-each-bar-equals-100.html" target="_blank" rel="noopener"&gt;https://blogs.sas.com/content/iml/2014/04/08/construct-a-stacked-bar-chart-in-sas-where-each-bar-equals-100.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To get the special colors, you can use the STYLEATTRS statement or a discrete attribute map. See&amp;nbsp;&lt;A href="https://blogs.sas.com/content/graphicallyspeaking/2014/10/19/consistent-group-colors-by-value/" target="_blank" rel="noopener"&gt;Consistent Group Colors by Value - Graphically Speaking&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Here is the creation of the stacked plot. You can use names or Hex values for assigning colors:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
    input lead $ north south east west;
datalines;
Joe 29 5 1 3
Suzie 4 6 8 19
Fred 109 8 2 36
Chris 235 48 29 54 
;

data Long;
   set new;
   Region = 1; Sales = north; output;
   Region = 2; Sales = south; output;
   Region = 3; Sales = east; output;
   Region = 4; Sales = west; output;
   keep Lead Region Sales;
run;

/* make a stacked bar chart with 100% 
   https://blogs.sas.com/content/iml/2014/04/08/construct-a-stacked-bar-chart-in-sas-where-each-bar-equals-100.html
*/

proc sort data=Long;
   by Lead Region;
run;

proc freq data=Long noprint order=data;
   by Lead;                        /* X categories on BY statement */
   tables Region / out=FreqOut;    /* Y (stacked groups) on TABLES statement */
   weight Sales;
run;

proc print; run;

/* assign names and colors to regions */
proc format;
value RegionFmt
      1 = "North"
      2 = "South" 
      3 = "East"
      4 = "West";
run;
%let MyColors = Green Yellow Red Cyan;

title "Sales Progress";
proc sgplot data=FreqOut;
   format Region RegionFmt.;
   styleattrs datacolors=(&amp;amp;MyColors);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;/CODE&gt;&lt;CODE class=" language-sas" style="font-size: 13px; white-space: normal;"&gt;&lt;/CODE&gt;&lt;CODE class=" language-sas" style="font-size: 13px; white-space: normal;"&gt; hbar Lead / response=Percent group=Region groupdisplay=stack outlineattrs=(color=darkgray);&lt;BR /&gt;&lt;/CODE&gt; &lt;CODE class=" language-sas" style="font-size: 13px; white-space: normal;"&gt;   yaxis discreteorder=data;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;   &lt;BR /&gt;    xaxis grid values=(0 to 100 by 10) label="Percentage of Total with Group";
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="SGPlot19.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/111217iDE53C39BDCAC60F7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SGPlot19.png" alt="SGPlot19.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Sat, 08 Nov 2025 10:44:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-a-horizontal-stacked-bar-chart/m-p/978542#M378623</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2025-11-08T10:44:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a horizontal stacked bar chart</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-a-horizontal-stacked-bar-chart/m-p/978619#M378651</link>
      <description>&lt;P&gt;That's PERFECT! THANK YOU. I truly appreciate it!&lt;/P&gt;</description>
      <pubDate>Mon, 10 Nov 2025 21:35:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-a-horizontal-stacked-bar-chart/m-p/978619#M378651</guid>
      <dc:creator>SASGeek</dc:creator>
      <dc:date>2025-11-10T21:35:07Z</dc:date>
    </item>
  </channel>
</rss>

