The main objective of this script is to visualize categorical data using a grouped bar chart. It first prepares a 'my_data' dataset using a DATALINES statement. Then, it configures the ODS destination system to generate HTML output, including an SGPLOT graphic in PNG format. The chart displays the sum of an 'AMOUNT' variable grouped by 'SERIES' and categorized by 'CATEGORY'. Style options are applied for better visual presentation, including a 3D shading on the bars ('dataskin=sheen'). Chart titles and axis attributes are also customized.
Data Analysis
Type : CREATION_INTERNE
The 'my_data' dataset is created internally within the script via a DATA step and the DATALINES statement. It contains three variables: 'CATEGORY', 'SERIES', and 'AMOUNT'.
1 Code Block
DATA STEP Data
Explanation : This block creates the 'my_data' dataset that will be used for the chart. Data is integrated directly into the script using the DATALINES statement, simulating data from various sources.
Copied!
data my_data;
input CATEGORY SERIES $ 3-11 AMOUNT;
datalines;
1 Series A 5
2 Series A 7.8
1 Series B 9.5
2 Series B 5.9
;
run;
1
DATA my_data;
2
INPUT CATEGORY SERIES $ 3-11 AMOUNT;
3
DATALINES;
4
1 Series A 5
5
2 Series A 7.8
6
1 Series B 9.5
7
2 Series B 5.9
8
;
9
RUN;
2 Code Block
ODS Configuration
Explanation : This block initializes the ODS (Output Delivery System) environment. It defines a macro variable 'name' to name the output files, closes the default ODS LISTING destination, and opens an ODS HTML destination to generate an HTML file. ODS GRAPHICS options are configured to produce a PNG image of the chart with specific dimensions, and titles are defined for the chart.
title2 color=gray33 ls=0.5 h=17pt "With 3D Shading";
3 Code Block
PROC SGPLOT
Explanation : This procedure generates the horizontal grouped bar chart. It uses the 'my_data' dataset. The HBAR statement creates the bars, summing 'AMOUNT' and grouping them by 'SERIES' within each 'CATEGORY'. The 'dataskin=sheen' option applies a 3D effect to the bars. Style and axis attributes are customized to improve readability and aesthetics of the chart.
dataskin=sheen /* <--- basically, added this line! */
6
outlineattrs=(color=black) nostatlabel;
7
xaxis
8
values=(0 to 10BY2)
9
labelattrs=(size=16pt weight=bold color=gray33)
10
valueattrs=(size=16pt weight=bold color=gray33)
11
offsetmax=0 grid minor minorcount=1;
12
yaxis
13
labelattrs=(size=16pt weight=bold color=gray33)
14
valueattrs=(size=16pt weight=bold color=gray33)
15
display=(noticks);
16
RUN;
4 Code Block
ODS Cleanup
Explanation : This block properly closes the open ODS destinations, particularly the ODS HTML destination, and reactivates the ODS LISTING destination. The 'quit' statement terminates any currently running SAS procedure.
Copied!
quit;
ODS HTML CLOSE;
ODS LISTING;
1
QUIT;
2
ODS HTML CLOSE;
3
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.