The script uses a DATA step to create a `my_data` dataset with categories, series, and amounts. It then configures ODS to produce HTML output and a PNG image file. The SGPLOT procedure is used to create a horizontal grouped bar chart (hbar) that visualizes the sum of amounts for different series within each category. Style options and custom titles are applied to the chart, and axes are formatted to improve readability. Finally, the ODS destinations are closed.
Data Analysis
Type : CREATION_INTERNE
The `my_data` dataset is created directly within the script using a DATA step and a DATALINES statement, providing data for categories A and B with their respective amounts.
1 Code Block
MACRO VAR
Explanation : Defines a macro variable `name` used to name the output HTML file and the PNG image.
Copied!
%let name=bar1;
1
%let name=bar1;
2 Code Block
FILENAME
Explanation : Assigns the `odsout` fileref to the current working directory, indicating where ODS output files will be saved.
Copied!
filename odsout '.';
1
filename odsout '.';
3 Code Block
DATA STEP Data
Explanation : Creates the `my_data` dataset containing information on `CATEGORY`, `SERIES` (character), and `AMOUNT` (numeric). Data is provided via an embedded `datalines` statement.
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;
4 Code Block
ODS
Explanation : Closes the default ODS LISTING destination and opens the ODS HTML destination, specifying the output path, the HTML file name (`bar1.htm`), a title for the HTML document, and the `htmlblue` style. `ods graphics` options are set to generate an 800x600px PNG image without a border and with an imagemap.
Explanation : Sets the main and secondary titles of the chart with color, spacing, and height options. `PROC SGPLOT` is used to create a horizontal grouped bar chart (`hbar`). Data comes from `my_data`. Bars are grouped by `series` and display the sum of `amount` for each `category`. Style attributes are applied to the bars and axes for improved visual rendering.
Explanation : Closes the ODS HTML destination and reactivates the ODS LISTING destination, thus completing the report generation process.
Copied!
ODS HTML CLOSE;
ODS LISTING;
1
ODS HTML CLOSE;
2
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.