The script begins by defining a macro variable 'name' and an 'odsout' fileref. It then creates a dataset named 'my_data' from inline data (datalines). A PROC SQL is used to add a 'bartotal' column to the dataset, representing the sum of 'amount' by 'category'. A second DATA STEP calculates 'catpct' (percentage of each 'amount' relative to 'bartotal') and formats this new variable as a percentage. Finally, it configures ODS options for HTML output, sets the chart titles, and uses PROC SGPLOT to create a stacked vertical bar chart. Key SGPLOT options include 'response=catpct', 'group=series', and 'dataskin=sheen' for the 3D effect.
Data Analysis
Type : CREATION_INTERNE
The 'my_data' dataset is entirely created at the beginning of the script using the DATALINES method. No external data or SASHELP library is used as an initial source.
1 Code Block
MACRO/GLOBAL
Explanation : Defines the macro variable 'name' as 'col6', which will be used to name the HTML output file and the image. 'filename odsout '.' ' directs the ODS output to the current working directory.
Copied!
%let name=col6;
filename odsout '.';
1
%let name=col6;
2
filename odsout '.';
2 Code Block
DATA STEP Data
Explanation : Creates the 'my_data' dataset with variables CATEGORY, SERIES (character), and AMOUNT (numeric) by reading data provided via the DATALINES statement.
Copied!
data my_data;
input CATEGORY SERIES $ 3-11 AMOUNT;
datalines;
1 Series A 5.0
2 Series A 6.8
3 Series A 9.2
1 Series B 6.5
2 Series B 6.9
3 Series B 5.6
1 Series C 2.3
2 Series C 3.1
3 Series C 2.3
;
run;
1
DATA my_data;
2
INPUT CATEGORY SERIES $ 3-11 AMOUNT;
3
DATALINES;
4
1 Series A 5.0
5
2 Series A 6.8
6
3 Series A 9.2
7
1 Series B 6.5
8
2 Series B 6.9
9
3 Series B 5.6
10
1 Series C 2.3
11
2 Series C 3.1
12
3 Series C 2.3
13
;
14
RUN;
3 Code Block
PROC SQL
Explanation : Modifies the 'my_data' dataset by adding a new 'bartotal' column. This column contains the sum of 'amount' for each 'category', calculated via SQL aggregation.
Copied!
proc sql;
create table my_data as
select *, sum(amount) as bartotal
from my_data
group by category;
quit; run;
1
PROC SQL;
2
create TABLE my_data as
3
select *, sum(amount) as bartotal
4
from my_data
5
group BY category;
6
QUIT; RUN;
4 Code Block
DATA STEP
Explanation : A second DATA STEP that reads the 'my_data' dataset, calculates the 'catpct' percentage of 'amount' relative to 'bartotal' for each observation, and applies a percentage format to this new variable.
Copied!
data my_data; set my_data;
format catpct percent6.0;
catpct=amount/bartotal;
run;
1
DATA my_data; SET my_data;
2
FORMAT catpct percent6.0;
3
catpct=amount/bartotal;
4
RUN;
5 Code Block
ODS/OPTIONS
Explanation : Closes the default LISTING output. Opens an ODS HTML destination, specifying the output path, the file name ('col6.htm'), a title for the HTML page, and an 'htmlblue' style. It then configures ODS graphics options to generate PNG images with a specific size, no border, and an image map. Finally, it defines two titles for the graph with color, size, and style properties.
title2 color=gray33 ls=0.5 h=17pt "With 3D Shading";
6 Code Block
PROC SGPLOT
Explanation : Uses PROC SGPLOT to create a stacked bar chart. Bars are defined by 'category' and stacked by 'series', with 'catpct' as the response variable. The 'dataskin=sheen' option adds a 3D effect. The style, colors, labels, and axis attributes are configured to enhance the chart's appearance. After execution, the ODS HTML destination is closed, and LISTING output is reopened.
dataskin=sheen /* <--- basically, added this line! */
7
outlineattrs=(color=black) nostatlabel;
8
yaxis
9
values=(0 to 1BY .2)
10
labelattrs=(size=16pt weight=bold color=gray33)
11
valueattrs=(size=16pt weight=bold color=gray33)
12
offsetmax=0 grid minor minorcount=1;
13
xaxis
14
labelattrs=(size=16pt weight=bold color=gray33)
15
valueattrs=(size=16pt weight=bold color=gray33)
16
display=(noticks);
17
RUN;
18
19
QUIT;
20
ODS HTML CLOSE;
21
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.