Sample 69831: Using the BAND statement to create a stacked band plot
This SAS Note provides a sample on using the BAND statement in PROC SGPLOT to create stacked filled areas for multiple group values.
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.
This sample code uses the BAND statement in PROC SGPLOT to create stacked filled areas for multiple group values.
/* Create sample daily data */
data bandGroup;
format Date Date9.;
do i=0 to 364 by 1;
date='01jan2022'd+i;
Drug='Drug A'; Val = 16+ 3*sin(i/90+0.5) + 1*sin(3*i/90+0.7); output;
Drug='Drug B'; Val = 11+ 3*sin(i/90+0.5) + 1*cos(3*i/90+0.7); output;
Drug='Drug C'; Val = 12+ 3*cos(i/90+0.5) + 1*sin(3*i/90+0.7); output;
end;
run;
/* calculate a lower and upper value for each group to
create a stacked band plot */
data stackBands;
set bandGroup;
by date;
if first.date then cumSum=0;
cumSum+Val;
lower=lag(cumSum);
if first.date then lower=0;
run;
title 'Stacked band plot';
proc sgplot data=stackBands;
/* define the band area fill colors */
styleattrs datacolors=(cx94b7da cxb6d2a2 cxdcc685);
/* draw the bands for each group */
band x=date lower=lower upper=cumSum / group=drug transparency=0.4 name='bands';
/* draw a line at the top of each band */
series x=date y=cumSum / group=drug lineattrs=(thickness=2px
pattern=1 color=black);
/* Define a legend to describe the filled areas */
keylegend 'bands' / across=1 position=topright location=inside;
yaxis grid display=(nolabel) offsetmin=0;
xaxis offsetmin=0 offsetmax=0 thresholdmax=1;
run;
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 ==> SGPLOT
|
Date Modified: | 2023-01-31 14:26:22 |
Date Created: | 2023-01-25 10:34:14 |
Operating System and Release Information
SAS System | Base SAS | z/OS | 9.4_M3 | | 9.4 TS1M3 | |
z/OS 64-bit | 9.4_M3 | | 9.4 TS1M3 | |
Microsoft® Windows® for x64 | 9.4_M3 | | 9.4 TS1M3 | |
Microsoft Windows 8 Enterprise 32-bit | 9.4_M3 | | 9.4 TS1M3 | |
Microsoft Windows 8 Enterprise x64 | 9.4_M3 | | 9.4 TS1M3 | |
Microsoft Windows 8 Pro 32-bit | 9.4_M3 | | 9.4 TS1M3 | |
Microsoft Windows 8 Pro x64 | 9.4_M3 | | 9.4 TS1M3 | |
Microsoft Windows 8.1 Enterprise 32-bit | 9.4_M3 | | 9.4 TS1M3 | |
Microsoft Windows 8.1 Enterprise x64 | 9.4_M3 | | 9.4 TS1M3 | |
Microsoft Windows 8.1 Pro 32-bit | 9.4_M3 | | 9.4 TS1M3 | |
Microsoft Windows 8.1 Pro x64 | 9.4_M3 | | 9.4 TS1M3 | |
Microsoft Windows 10 | 9.4_M3 | | 9.4 TS1M3 | |
Microsoft Windows Server 2008 | 9.4_M3 | | 9.4 TS1M3 | |
Microsoft Windows Server 2008 R2 | 9.4_M3 | | 9.4 TS1M3 | |
Microsoft Windows Server 2008 for x64 | 9.4_M3 | | 9.4 TS1M3 | |
Microsoft Windows Server 2012 Datacenter | 9.4_M3 | | 9.4 TS1M3 | |
Microsoft Windows Server 2012 R2 Datacenter | 9.4_M3 | | 9.4 TS1M3 | |
Microsoft Windows Server 2012 R2 Std | 9.4_M3 | | 9.4 TS1M3 | |
Microsoft Windows Server 2012 Std | 9.4_M3 | | 9.4 TS1M3 | |
Windows 7 Enterprise 32 bit | 9.4_M3 | | 9.4 TS1M3 | |
Windows 7 Enterprise x64 | 9.4_M3 | | 9.4 TS1M3 | |
Windows 7 Home Premium 32 bit | 9.4_M3 | | 9.4 TS1M3 | |
Windows 7 Home Premium x64 | 9.4_M3 | | 9.4 TS1M3 | |
Windows 7 Professional 32 bit | 9.4_M3 | | 9.4 TS1M3 | |
Windows 7 Professional x64 | 9.4_M3 | | 9.4 TS1M3 | |
Windows 7 Ultimate 32 bit | 9.4_M3 | | 9.4 TS1M3 | |
Windows 7 Ultimate x64 | 9.4_M3 | | 9.4 TS1M3 | |
64-bit Enabled AIX | 9.4_M3 | | 9.4 TS1M3 | |
64-bit Enabled Solaris | 9.4_M3 | | 9.4 TS1M3 | |
HP-UX IPF | 9.4_M3 | | 9.4 TS1M3 | |
Linux for x64 | 9.4_M3 | | 9.4 TS1M3 | |
Solaris for x64 | 9.4_M3 | | 9.4 TS1M3 | |