The script initializes a 'my_data' dataset from inline data (datalines). It then configures the ODS destination system to generate HTML output and a PNG graphic. A PROC SGPLOT is used to create a horizontal stacked bar chart. The bars are styled with a 3D effect ('dataskin=sheen') and axes are customized for better readability. The chart is saved to an HTML file and a PNG image, with specific titles.
Data Analysis
Type : CREATION_INTERNE
The 'my_data' dataset is created directly within the script using a DATA step and the DATALINES statement. It contains variables for category, series, and amount.
1 Code Block
Macro Variable / FILENAME
Explanation : Defines a macro variable `name` to name the output files (HTML, PNG) and assigns an `odsout` fileref to the current working directory, allowing output files to be written there.
Copied!
%let name=bar4;
filename odsout '.';
1
%let name=bar4;
2
3
filename odsout '.';
2 Code Block
DATA STEP Data
Explanation : Creates the SAS dataset named 'my_data' using a DATA step and the DATALINES statement. The inline data is read into three variables: 'CATEGORY' (numeric), 'SERIES' (character), and 'AMOUNT' (numeric).
Copied!
data my_data;
input CATEGORY SERIES $ 3-11 AMOUNT;
datalines;
1 Series A 5
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
;
run;
1
DATA my_data;
2
INPUT CATEGORY SERIES $ 3-11 AMOUNT;
3
DATALINES;
4
1 Series A 5
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
;
11
RUN;
3 Code Block
ODS Configuration
Explanation : Configures the ODS (Output Delivery System) destination system to generate HTML output and graphics. The ODS LISTING destination is closed, and ODS HTML is activated to create an HTML file ('bar4.htm') with a title and 'htmlblue' style. ODS GRAPHICS is configured to produce a PNG image ('bar4.png') of 800x600 pixels without a border. Two titles are defined for the chart with specific styles and colors.
title2 color=gray33 ls=0.5 h=17pt "With 3D Shading";
4 Code Block
PROC SGPLOT
Explanation : Executes PROC SGPLOT to create a horizontal stacked bar chart from the 'my_data' dataset. Style attributes define data colors. The `hbar` statement creates the bars, using 'CATEGORY' for the Y-axis, 'AMOUNT' for the X-axis (with sum as statistic), and 'SERIES' to group the bars. The 'dataskin=sheen' option applies a 3D effect. X and Y axes are customized in terms of values, labels, text attributes, and display.
dataskin=sheen /* <--- basically, added this line! */
6
outlineattrs=(color=black) nostatlabel;
7
xaxis
8
values=(0 to 16BY4)
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;
5 Code Block
ODS Cleanup
Explanation : Ends the current SGPLOT procedure, then closes the ODS HTML destination, and finally reactivates the ODS LISTING destination to return to the default SAS output state.
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.