Published on :
Reporting CREATION_INTERNE

3D Grouped Bar Chart Generation with ODS HTML

This code is also available in: Deutsch Español Français
Awaiting validation
The script initializes a macro variable 'name' used for the output file name. It creates a dataset 'my_data' using in-line data (`datalines`), which allows the script to be self-contained. The Output Delivery System (ODS) is configured to close LISTING output and open HTML output, specifying the output directory ('odsout') and the HTML file name. ODS graphic options are set to generate a PNG image with specific dimensions and an imagemap. Custom titles are added to the chart. The PROC SGPLOT procedure is then used to create a grouped bar chart ('vbar') where the Y-axis represents the amount ('AMOUNT') and the X-axis represents the 'CATEGORY', grouped by 'SERIES'. The 'dataskin=sheen' attribute gives the bars a 3D effect. Bar colors, axis label attributes, and the grid are also customized. After chart generation, the HTML output is closed, and LISTING output is reopened.
Data Analysis

Type : CREATION_INTERNE


The 'my_data' dataset is entirely created within the script using a DATA STEP instruction with embedded data via 'datalines'. This ensures the script's independence from external data sources.

1 Code Block
DATA STEP Data
Explanation :
This DATA STEP block creates the 'my_data' dataset from data provided directly within the script (datalines). It defines three variables: 'CATEGORY' (numeric), 'SERIES' (character string), and 'AMOUNT' (numeric).
Copied!
1DATA my_data;
2INPUT CATEGORY SERIES $ 3-11 AMOUNT;
3DATALINES;
41 Series A 5
52 Series A 7.8
61 Series B 9.5
72 Series B 5.9
8;
9RUN;
2 Code Block
PROC SGPLOT
Explanation :
This block handles report generation and visualization. It configures the ODS system to produce HTML output with the chart. PROC SGPLOT is used to create a grouped bar chart (vbar) based on the 'my_data' dataset. Options include custom data colors, grouping by 'SERIES', a 3D effect ('dataskin=sheen'), and detailed axis and title customizations for better visual presentation.
Copied!
1ODS LISTING CLOSE;
2ODS HTML path=odsout body="&name..htm"
3 (title="SGplot Grouped Bar (3D)")
4 style=htmlblue;
5 
6ods graphics / imagefmt=png imagename="&name"
7 width=800px height=600px noborder imagemap;
8 
9title1 color=gray33 ls=0.5 h=23pt "Grouped Bar";
10title2 color=gray33 ls=0.5 h=17pt "With 3D Shading";
11 
12PROC SGPLOT DATA=my_data noautolegend;
13styleattrs datacolors=(cx9999ff cx993366);
14vbar category / response=amount stat=sum
15 group=series groupdisplay=cluster
16 dataskin=sheen /* <--- basically, added this line! */
17 outlineattrs=(color=black) nostatlabel;
18yaxis
19 values=(0 to 10 BY 2)
20 labelattrs=(size=16pt weight=bold color=gray33)
21 valueattrs=(size=16pt weight=bold color=gray33)
22 offsetmax=0 grid minor minorcount=1;
23xaxis
24 labelattrs=(size=16pt weight=bold color=gray33)
25 valueattrs=(size=16pt weight=bold color=gray33)
26 labelpos=right;
27RUN;
28 
29QUIT;
30ODS HTML CLOSE;
31ODS 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.