These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
/* Set the graphics environment */
goptions reset=all cback=white border htitle=12pt htext=10pt;
/* Sum the total sales by product for each country */
proc sort data=sashelp.prdsale out=prdsale;
by product country;
run;
proc means data=prdsale noprint;
by product country;
var actual;
output out=meansout sum=actual_sum;
run;
/* Sort the data set by the midpoint and subgroup variables */
proc sort data=meansout;
by product country;
run;
/* Calculate the center location for each subgroup. */
/* Store the value in a Middle variable. */
data middle;
set meansout;
by product country;
retain temp_sum;
if first.product then temp_sum=actual_sum;
else temp_sum + actual_sum;
middle=(actual_sum/2)+lag(temp_sum);
if first.product then middle=actual_sum/2;
run;
/* Create an Annotate data set to draw labels */
/* for the summed values for each subgroup. */
data barlabel;
length function color $8;
retain xsys ysys '2' color 'black' when 'a';
set middle;
function='label';
midpoint=product;
subgroup=country;
x=middle;
position='+';
text=trim(left(put(actual_sum,dollar8.0)));
run;
/* Define the title */
title1 "Center the Subgroup Labels in a Horizontal Bar Chart";
/* Define the axis characteristics */
axis1 label=(angle=90 "Product")
value=(justify=right);
axis2 label=("Actual Sales")
order=(0 to 160000 by 40000)
minor=(n=3);
/* Define legend options */
legend1 frame;
/* Generate the graph */
proc gchart data=sashelp.prdsale;
hbar product / subgroup=country
sumvar=actual
legend=legend1
nostats
maxis=axis1
raxis=axis2
annotate=barlabel;
format actual dollar8.0;
run;
quit;
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
Type: | Sample |
Topic: | SAS Reference ==> Procedures ==> GCHART Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Elements ==> Annotation Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Types ==> Charts ==> Bar |
Date Modified: | 2012-11-12 12:43:37 |
Date Created: | 2012-11-12 11:35:16 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | SAS/GRAPH | z/OS | 9.1 TS1M3 | |
Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.1 TS1M3 | |||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.1 TS1M3 | |||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.1 TS1M3 | |||
Microsoft Windows XP 64-bit Edition | 9.1 TS1M3 | |||
Microsoft Windows 2000 Advanced Server | 9.1 TS1M3 | |||
Microsoft Windows 2000 Datacenter Server | 9.1 TS1M3 | |||
Microsoft Windows 2000 Server | 9.1 TS1M3 | |||
Microsoft Windows 2000 Professional | 9.1 TS1M3 | |||
Microsoft Windows NT Workstation | 9.1 TS1M3 | |||
Microsoft Windows Server 2003 Datacenter Edition | 9.1 TS1M3 | |||
Microsoft Windows Server 2003 Enterprise Edition | 9.1 TS1M3 | |||
Microsoft Windows Server 2003 Standard Edition | 9.1 TS1M3 | |||
Microsoft Windows XP Professional | 9.1 TS1M3 | |||
Windows Vista | 9.1 TS1M3 | |||
Windows Vista for x64 | 9.1 TS1M3 | |||
64-bit Enabled AIX | 9.1 TS1M3 | |||
64-bit Enabled HP-UX | 9.1 TS1M3 | |||
64-bit Enabled Solaris | 9.1 TS1M3 | |||
HP-UX IPF | 9.1 TS1M3 | |||
Linux | 9.1 TS1M3 | |||
OpenVMS Alpha | 9.1 TS1M3 | |||
Tru64 UNIX | 9.1 TS1M3 |