This script illustrates the creation of a 'Stacked Area Plot' using the SGPLOT procedure. It first creates an internal dataset containing coordinates and calculated bases for stacking. Then, it configures the ODS output to generate an HTML file and a PNG image. The plot uses the BAND statement to draw the areas between the calculated variables.
Data Analysis
Type : INTERNAL_CREATION
Data is explicitly defined in the 'my_data' Data Step using the DATALINES statement.
1 Code Block
DATA STEP Data
Explanation : Definition of the output name and creation of the 'my_data' dataset with calculation of 'base1', 'base2', and 'y2_stacked' variables required for graphically stacking the areas.
Explanation : Configuration of ODS output (HTML and PNG), title definition, and execution of the SGPLOT procedure. The BAND statement is used twice to draw the stacked layers, and axes are customized.
Copied!
ODS LISTING CLOSE;
ODS HTML path=odsout body="&name..htm"
(title="SGplot Stacked Area Plot")
style=htmlblue;
ods graphics / imagefmt=png imagename="&name"
width=800px height=600px noborder;
title1 color=gray33 ls=0.0 h=23pt "Stacked Area Plot";
proc sgplot data=my_data noautolegend;
styleattrs datacolors=(cx993366 cx9999ff);
band x=x lower=base1 upper=y1;
band x=x lower=base2 upper=y2_stacked;
yaxis
values=(0 to 4 by 1) label='Y Axis'
labelattrs=(size=16pt weight=bold color=gray33)
valueattrs=(size=16pt weight=bold color=gray33)
offsetmin=0 offsetmax=0 grid;
xaxis
values=(0 to 5 by 1) label='X Axis'
labelattrs=(size=16pt weight=bold color=gray33)
valueattrs=(size=16pt weight=bold color=gray33)
offsetmin=0 offsetmax=0 grid;
run;
quit;
ODS HTML CLOSE;
ODS LISTING;
1
ODS LISTING CLOSE;
2
ODS HTML path=odsout body="&name..htm"
3
(title="SGplot Stacked Area Plot")
4
style=htmlblue;
5
6
ods graphics / imagefmt=png imagename="&name"
7
width=800px height=600px noborder;
8
9
title1 color=gray33 ls=0.0 h=23pt "Stacked Area Plot";
10
11
PROC SGPLOTDATA=my_data noautolegend;
12
styleattrs datacolors=(cx993366 cx9999ff);
13
band x=x lower=base1 upper=y1;
14
band x=x lower=base2 upper=y2_stacked;
15
yaxis
16
values=(0 to 4BY1) label='Y Axis'
17
labelattrs=(size=16pt weight=bold color=gray33)
18
valueattrs=(size=16pt weight=bold color=gray33)
19
offsetmin=0 offsetmax=0 grid;
20
xaxis
21
values=(0 to 5BY1) label='X Axis'
22
labelattrs=(size=16pt weight=bold color=gray33)
23
valueattrs=(size=16pt weight=bold color=gray33)
24
offsetmin=0 offsetmax=0 grid;
25
RUN;
26
27
QUIT;
28
ODS HTML CLOSE;
29
ODS LISTING;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.