You can generate a stacked area plot in which the areas are drawn cumulatively on top of each other. However, PROC GPLOT does not have the capability to sum the Y values for each area. You need to calculate the accumulated Y-axis values in a DATA step prior to creating the graph.
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.
You can generate a stacked area plot in which the areas are drawn cumulatively on top of each other. However, PROC GPLOT does not have the capability to sum the Y values for each area. You need to calculate the accumulated Y-axis values in a DATA step prior to creating the graph.
The graphics output in the Results tab was produced using SAS® 9.2. Submitting the sample code with releases of SAS prior to SAS 9.2 might produce different results.
/* Set the graphics environment */
goptions reset=all cback=white border htitle=12pt htext=10pt;
/* Create sample data to plot. */
data test;
do area_var=1 to 3;
do xvar=1 to 10;
yvar=ranuni(0)*100;
output;
end;
end;
run;
/* Sort by the X-axis variable and the area variable. */
proc sort data=test;
by xvar area_var;
run;
/* Stack the areas by accumulating */
/* the Y values for each X value. */
data test2;
set test;
by xvar area_var;
if first.xvar then new_y=0;
new_y + yvar;
run;
/* Define the title */
title1 "Stacked Area Plot";
/* Define the axis characteristics */
axis1 label=('X value')
offset=(0,0);
axis2 label=(angle=90 'Y value')
offset=(0,0);
/* Define the symbol characteristics. */
/* Join the points to define the areas. */
symbol1 interpol=join repeat=3;
/* Define the legend options */
legend1 label=('Area') frame
shape=bar(6,1);
/* Generate the graph */
proc gplot data=test2;
plot new_y*xvar=area_var / areas=3 legend=legend1
haxis=axis1 vaxis=axis2;
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 ==> GPLOT Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Types ==> Plots ==> Area |
Date Modified: | 2017-10-30 13:05:47 |
Date Created: | 2011-03-01 12:36:13 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | SAS/GRAPH | Tru64 UNIX | 9.1 TS1M0 | |
OpenVMS Alpha | 9.1 TS1M0 | |||
Linux | 9.1 TS1M0 | |||
HP-UX IPF | 9.1 TS1M0 | |||
64-bit Enabled Solaris | 9.1 TS1M0 | |||
64-bit Enabled HP-UX | 9.1 TS1M0 | |||
64-bit Enabled AIX | 9.1 TS1M0 | |||
Microsoft Windows XP Professional | 9.1 TS1M0 | |||
Microsoft Windows Server 2003 Standard Edition | 9.1 TS1M0 | |||
Microsoft Windows Server 2003 Enterprise Edition | 9.1 TS1M0 | |||
Microsoft Windows Server 2003 Datacenter Edition | 9.1 TS1M0 | |||
Microsoft Windows NT Workstation | 9.1 TS1M0 | |||
Microsoft Windows 2000 Professional | 9.1 TS1M0 | |||
Microsoft Windows 2000 Server | 9.1 TS1M0 | |||
Microsoft Windows 2000 Datacenter Server | 9.1 TS1M0 | |||
Microsoft Windows 2000 Advanced Server | 9.1 TS1M0 | |||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.1 TS1M0 | |||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.1 TS1M0 | |||
Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.1 TS1M0 | |||
z/OS | 9.1 TS1M0 |