Published on :

Generating Graphs and Tables with ODS HTMLPANEL

This code is also available in: Deutsch Español Français
Awaiting validation
This SAS© script illustrates the use of the ODS TAGSETS.HTMLPANEL destination to create a consolidated HTML report. It begins by creating an internal dataset 'one' via a DATA STEP. Then, it configures ODS HTMLPANEL to automatically group several graphs generated by PROC GCHART and PROC GPLOT into a single panel. The graphs are based on the SASHELP.CLASS dataset. After the panel, a PROC PRINT table is generated, followed by a grouped graph (BY-group processing) created from the 'one' dataset. The script also uses GOPTIONS for graphic configuration and TITLE/FOOTNOTE statements for report customization.
Data Analysis

Type : MIXTE


The script uses two data sources: SASHELP.CLASS (a demonstration dataset built into SAS) and an internal dataset 'one' created directly in the script via a DATALINES statement (CREATION_INTERNE).

1 Code Block
DATA STEP Data
Explanation :
This DATA STEP block creates a dataset named 'one' using inline data (DATALINES/CARDS). It contains three variables (x, y, z) and 12 observations, intended for later use in group analyses.
Copied!
1DATA one;
2 INPUT x y z;
3 CARDS;
41 10 1
52 20 1
63 30 1
71 40 2
82 50 2
93 60 2
101 10 3
112 20 3
123 30 3
131 40 4
142 50 4
153 60 4
16;
17RUN;
2 Code Block
ODS TAGSETS.HTMLPANEL / GOPTIONS
Explanation :
This block initializes the ODS TAGSETS.HTMLPANEL destination to create an HTML file ('gpanelall.html') that will act as a container for the graphs. The 'panelcolumns' and 'panelborder' options define the panel layout. GOPTIONS configures graphic parameters, specifying the device driver (JAVAIMG) and pixel dimensions for the generated images.
Copied!
1%let panelcolumns = 2;
2%let panelborder = 1;
3 
4ods tagsets.htmlpanel path="." (url=none) file="gpanelall.html";
5goptions dev=javaimg xpixels=480 ypixels=320;
3 Code Block
TITLES/FOOTNOTES
Explanation :
This block defines global titles (title1, title2) and footnotes (footnote1, footnote2) that will be applied to subsequent graphic outputs, except for those specifically canceled or replaced.
Copied!
1title1 "Health analysis";
2title2 "using Gchart and Gplot";
3footnote1 "A footnote";
4footnote2 "A second footnote";
4 Code Block
PROC GCHART / PROC GPLOT
Explanation :
This block activates ODS HTMLPANEL's automatic paneling mode. Several graphic procedures are executed consecutively: two PROC GCHART (vertical and horizontal bar charts of age and weight/height) and two PROC GPLOT (scatter plots of weight vs height and height vs weight). All these graphic outputs will be automatically grouped into a panel in the final HTML file. SYMBOL statements define markers and colors for GPLOT graphs.
Copied!
1ods tagsets.htmlpanel event=panel(start);
2 
3 PROC GCHART DATA=sashelp.class;
4 vbar age / sumvar=height pattid=midpoint;
5 RUN;
6 QUIT;
7 
8 PROC GCHART DATA=sashelp.class;
9 hbar age / sumvar=weight pattid=midpoint;
10 RUN;
11 QUIT;
12
13symbol1 c=red v=plus;
14 PROC GPLOT DATA=sashelp.class;
15 plot weight*height;
16 RUN;
17 QUIT;
18
19symbol1 c=blue v=circle;
20 PROC GPLOT DATA=sashelp.class;
21 plot height*weight;
22 RUN;
23 QUIT;
24 
25ods tagsets.htmlpanel event=panel(finish);
5 Code Block
PROC PRINT
Explanation :
This block generates a simple table using PROC PRINT to display the content of the SASHELP.CLASS dataset. A new title is defined specifically for this table, replacing previous titles.
Copied!
1title1 "A
2PROC PRINT Table";
3PROC PRINT
4DATA=sashelp.class;
5RUN;
6 
6 Code Block
PROC GCHART (BY-group)
Explanation :
This block creates a vertical bar chart (vbar) with PROC GCHART. The BY Z statement indicates that the graph will be generated separately for each unique value of the 'z' variable in the 'one' dataset, allowing for group analysis. The graph displays the sum of 'y' by 'x'.
Copied!
1title1 "A by-group";
2PROC GCHART DATA=one;
3 BY z;
4 vbar x / sumvar=y pattid=midpoint discrete;
5RUN;
6QUIT;
7 Code Block
ODS _ALL_ CLOSE
Explanation :
This statement closes all currently open ODS destinations, including ODS TAGSETS.HTMLPANEL, thus finalizing the creation of output files.
Copied!
1ods _all_ close;
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.