The script begins by defining a macro variable `name`. It then creates a dataset named `my_data` using a DATA step with `datalines` to include the data directly within the script. This data contains information on categories, series, and amounts. The script then uses ODS (Output Delivery System) to generate HTML output containing an SGPLOT graph. The graph is a horizontal stacked bar chart that compares amounts by `CATEGORY`, grouped by `SERIES`. Style attributes and titles are applied to the chart. The image is exported in PNG format within the HTML file.
Data Analysis
Type : INTERNAL_CREATION
Data is created directly within the script via a DATA step and the DATALINES statement.
1 Code Block
Macro/Global
Explanation : Defines a macro variable `name` used for the output filename and assigns the `odsout` fileref to the current directory.
Copied!
%let name=bar3;
filename odsout '.';
1
%let name=bar3;
2
filename odsout '.';
2 Code Block
DATA STEP Data
Explanation : Creates the `my_data` dataset by reading embedded raw data (datalines) with CATEGORY, SERIES, and AMOUNT variables.
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
Explanation : Closes the default LISTING output and opens an ODS HTML environment to generate the report. Specifies the output path, HTML filename, and style.
Explanation : Defines the main and secondary chart titles with specific color, size, and font options.
Copied!
title1 color=gray33 ls=0.5 h=23pt "Horizontal Stacked Bar";
title2 color=gray33 ls=0.5 h=17pt "Compares the contribution of each value";
title3 color=gray33 ls=0.5 h=17pt "to a total across categories";
title2 color=gray33 ls=0.5 h=17pt "Compares the contribution of each value";
3
title3 color=gray33 ls=0.5 h=17pt "to a total across categories";
4
6 Code Block
PROC SGPLOT
Explanation : Executes the SGPLOT procedure to create a horizontal stacked bar chart. Uses `my_data`, specifies bar colors, X-axis (response and statistic), and Y-axis (category) with formatting and style options.
Explanation : Ends the SGPLOT procedure (`quit`), closes the ODS HTML file, and reactivates the default LISTING output.
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.