<?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: Creating Horizontal Bars for two variables in one chart in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/Creating-Horizontal-Bars-for-two-variables-in-one-chart/m-p/67923#M2351</link>
    <description>Hi:&lt;BR /&gt;
  If you have data that is structured like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
 Region Sales2009 Sales2010&lt;BR /&gt;
 East    543       487&lt;BR /&gt;
 North   500       565&lt;BR /&gt;
 South   825       750&lt;BR /&gt;
 West    600       700&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                     &lt;BR /&gt;
Then you need to use something like PROC TRANSPOSE or a DATA step program to restructure the data so it looks like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
 Region      Year       Sales&lt;BR /&gt;
 East      sales2009     543&lt;BR /&gt;
 East      sales2010     487&lt;BR /&gt;
 North     sales2009     500&lt;BR /&gt;
 North     sales2010     565&lt;BR /&gt;
 South     sales2009     825&lt;BR /&gt;
 South     sales2010     750&lt;BR /&gt;
 West      sales2009     600&lt;BR /&gt;
 West      sales2010     700&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                          &lt;BR /&gt;
PROC GCHART is more able to plot the bars in groups and subgroups when the numeric variable has the same name and the grouping or subgrouping variable has the value that will make up the separate bars and/or separate groups.&lt;BR /&gt;
 &lt;BR /&gt;
For example, if you have the restructured data (as shown above) in a file called WORK.GRF_OUT, then a PROC GCHART that would give you a horizontal bar chart with the differing years and regions grouped together would be code similar to this. Change the SPACE and GSPACE= values to adjust the space between the individual bars and the bars for each group.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
 &lt;BR /&gt;
[pre]&lt;BR /&gt;
proc gchart data=grf_out;&lt;BR /&gt;
  hbar year / type=sum sumvar=sales&lt;BR /&gt;
       group=region subgroup=year &lt;BR /&gt;
       space=0 coutline=same&lt;BR /&gt;
       gspace=5;&lt;BR /&gt;
  label year='Year'&lt;BR /&gt;
        region='Region'&lt;BR /&gt;
        sales='Sales';&lt;BR /&gt;
run;&lt;BR /&gt;
quit;&lt;BR /&gt;
[/pre]</description>
    <pubDate>Sat, 28 Aug 2010 02:19:06 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2010-08-28T02:19:06Z</dc:date>
    <item>
      <title>Creating Horizontal Bars for two variables in one chart</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Creating-Horizontal-Bars-for-two-variables-in-one-chart/m-p/67922#M2350</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I need help in creating a chart where I can see the bars for two variables (say sales last year and sales this year).&lt;BR /&gt;
&lt;BR /&gt;
For example if I have a variable called region and it has 4 values - North, South, East and West and each of this regions has values of last year sales and this year sales ( this sales are in different variables) Now I want the chart with horizontal bars such that I can see the bar for this year and last year one below the other for each region. Can some one please help with the proc gchart code for this?&lt;BR /&gt;
&lt;BR /&gt;
Thanks&lt;BR /&gt;
Sohail Mohammad</description>
      <pubDate>Sat, 28 Aug 2010 00:20:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Creating-Horizontal-Bars-for-two-variables-in-one-chart/m-p/67922#M2350</guid>
      <dc:creator>Soha</dc:creator>
      <dc:date>2010-08-28T00:20:16Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Horizontal Bars for two variables in one chart</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Creating-Horizontal-Bars-for-two-variables-in-one-chart/m-p/67923#M2351</link>
      <description>Hi:&lt;BR /&gt;
  If you have data that is structured like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
 Region Sales2009 Sales2010&lt;BR /&gt;
 East    543       487&lt;BR /&gt;
 North   500       565&lt;BR /&gt;
 South   825       750&lt;BR /&gt;
 West    600       700&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                     &lt;BR /&gt;
Then you need to use something like PROC TRANSPOSE or a DATA step program to restructure the data so it looks like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
 Region      Year       Sales&lt;BR /&gt;
 East      sales2009     543&lt;BR /&gt;
 East      sales2010     487&lt;BR /&gt;
 North     sales2009     500&lt;BR /&gt;
 North     sales2010     565&lt;BR /&gt;
 South     sales2009     825&lt;BR /&gt;
 South     sales2010     750&lt;BR /&gt;
 West      sales2009     600&lt;BR /&gt;
 West      sales2010     700&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                          &lt;BR /&gt;
PROC GCHART is more able to plot the bars in groups and subgroups when the numeric variable has the same name and the grouping or subgrouping variable has the value that will make up the separate bars and/or separate groups.&lt;BR /&gt;
 &lt;BR /&gt;
For example, if you have the restructured data (as shown above) in a file called WORK.GRF_OUT, then a PROC GCHART that would give you a horizontal bar chart with the differing years and regions grouped together would be code similar to this. Change the SPACE and GSPACE= values to adjust the space between the individual bars and the bars for each group.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
 &lt;BR /&gt;
[pre]&lt;BR /&gt;
proc gchart data=grf_out;&lt;BR /&gt;
  hbar year / type=sum sumvar=sales&lt;BR /&gt;
       group=region subgroup=year &lt;BR /&gt;
       space=0 coutline=same&lt;BR /&gt;
       gspace=5;&lt;BR /&gt;
  label year='Year'&lt;BR /&gt;
        region='Region'&lt;BR /&gt;
        sales='Sales';&lt;BR /&gt;
run;&lt;BR /&gt;
quit;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Sat, 28 Aug 2010 02:19:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Creating-Horizontal-Bars-for-two-variables-in-one-chart/m-p/67923#M2351</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-08-28T02:19:06Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Horizontal Bars for two variables in one chart</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Creating-Horizontal-Bars-for-two-variables-in-one-chart/m-p/67924#M2352</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ho Soha&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can also use the SG... procs to achieve the result, see example below. They allow to overlay plots with some settings for barwidth and discreteoffset you get two bar beside each other. With this example there is no need to change our data&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;DIV style="font-family: Consolas; font-size: 14pt;"&gt;&lt;STRONG style="color: #000080; background-color: #ffffff;"&gt;data&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; plotData;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;infile&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;cards&lt;/SPAN&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;input&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Region $&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Sales2009&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Sales2010&lt;BR /&gt;&amp;nbsp; ;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;cards&lt;/SPAN&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffc0;"&gt;East&amp;nbsp; 543 487&lt;BR /&gt;North 500 565&lt;BR /&gt;South 825 750&lt;BR /&gt;West&amp;nbsp; 600 700&lt;BR /&gt;&lt;/SPAN&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG style="color: #000080; background-color: #ffffff;"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: #000080; background-color: #ffffff;"&gt;sgplot&lt;/STRONG&gt; &lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;data&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;=plotData;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;hbar&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; region / &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;response&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;=sales2009&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; discreteoffset=-&lt;/SPAN&gt;&lt;STRONG style="color: #008080; background-color: #ffffff;"&gt;0.2&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;barwidth&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;=&lt;/SPAN&gt;&lt;STRONG style="color: #008080; background-color: #ffffff;"&gt;0.4&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp; ;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;hbar&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; region / &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;response&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;=sales2010&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; discreteoffset=&lt;/SPAN&gt;&lt;STRONG style="color: #008080; background-color: #ffffff;"&gt;0.2&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;barwidth&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;=&lt;/SPAN&gt;&lt;STRONG style="color: #008080; background-color: #ffffff;"&gt;0.4&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;transparency&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;=&lt;/SPAN&gt;&lt;STRONG style="color: #008080; background-color: #ffffff;"&gt;0.5&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp; ;&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG style="color: #000080; background-color: #ffffff;"&gt;run&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Oct 2012 15:22:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Creating-Horizontal-Bars-for-two-variables-in-one-chart/m-p/67924#M2352</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2012-10-29T15:22:46Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Horizontal Bars for two variables in one chart</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Creating-Horizontal-Bars-for-two-variables-in-one-chart/m-p/67925#M2353</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;DISCRETEOFFSET is supported with SAS 9.3 SGPLOT.&amp;nbsp; You can turn off stat labels to remove the (Sum) suffix to the label in the legend.&amp;nbsp; You can also creatively set bar width and discrete offsets to get an overlap effect or separate the bars completely.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;title 'Sales by Region';&lt;/P&gt;&lt;P&gt;ods listing style=listing;&lt;/P&gt;&lt;P&gt;proc sgplot data=plotData cycleattrs;&lt;/P&gt;&lt;P&gt;&amp;nbsp; hbar region / nostatlabel response=sales2009 discreteoffset=-0.2 barwidth=0.5;&lt;/P&gt;&lt;P&gt;&amp;nbsp; hbar region / nostatlabel response=sales2010 discreteoffset=0.2&amp;nbsp; barwidth=0.5;&lt;/P&gt;&lt;P&gt;&amp;nbsp; xaxis display=(nolabel);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Oct 2012 16:15:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Creating-Horizontal-Bars-for-two-variables-in-one-chart/m-p/67925#M2353</guid>
      <dc:creator>Jay54</dc:creator>
      <dc:date>2012-10-29T16:15:41Z</dc:date>
    </item>
  </channel>
</rss>

