Published on :

Panelization of ODS Graphics and Reports

This code is also available in: Deutsch Español Français
Awaiting validation
The script begins by creating an internal dataset 'one' via a DATA step with inline data. It then sets up macro variables for the ODS panel and initializes ODS TAGSETS.HTMLPANEL to generate an HTML file named 'gtfpanel.html'. Graphics options (GOPTIONS) are defined to specify the driver and dimensions, and footnotes are specified. Four PROC GCHART graphs are generated from the SASHELP.CLASS dataset and are automatically panelized in the HTML output. A simple table is then displayed with PROC PRINT from the 'one' dataset. Finally, an additional PROC GCHART graph is generated with grouping by the 'z' variable from the 'one' dataset, demonstrating by-group titles and footnotes. The script concludes by disabling embedded titles and closing all ODS destinations.
Data Analysis

Type : MIXTE


The script uses an internally created dataset ('one') via a DATA step with inline data, and the SASHELP.CLASS system dataset.

1 Code Block
DATA STEP Data
Explanation :
Creates a dataset named 'one' with three variables (x, y, z) and inserts inline defined data (datalines).
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
Configuration
Explanation :
Defines macro variables to control the panel display (number of columns, border, embedded titles) and opens the ODS TAGSETS.HTMLPANEL destination to generate an HTML file named 'gtfpanel.html' in the current directory.
Copied!
1%let panelcolumns = 2;
2%let panelborder = 1;
3%let embedded_titles=yes;
4 
5ods tagsets.htmlpanel path="." (url=none) file="gtfpanel.html";
3 Code Block
GOPTIONS & FOOTNOTE
Explanation :
Configures global graphics options, specifying the 'javaimg' device driver and pixel dimensions. Also defines two footnotes that will be used for subsequent graphs.
Copied!
1goptions dev=javaimg xpixels=480 ypixels=320;
2 
3/* Footnote stuff */
4footnote1 "A footnote";
5footnote2 "A second footnote";
4 Code Block
PROC GCHART
Explanation :
Starts ODS panelization. Generates four bar charts (vertical and horizontal) from the `sashelp.class` dataset using PROC GCHART. Each chart receives a distinct title. These charts are automatically organized into a panel in the HTML output. Panelization is stopped after the graphs are generated.
Copied!
1ods tagsets.htmlpanel event=panel(start);
2 
3 title1 "Chart 1";
4 PROC GCHART DATA=sashelp.class;
5 vbar age;
6 RUN;
7 QUIT;
8 
9 title1 "Chart 2";
10 PROC GCHART DATA=sashelp.class;
11 hbar age;
12 RUN;
13 QUIT;
14 
15 title1 "Chart 3";
16 PROC GCHART DATA=sashelp.class;
17 vbar age / pattid=midpoint;
18 RUN;
19 QUIT;
20 
21 title1 "Chart 4";
22 PROC GCHART DATA=sashelp.class;
23 hbar age / pattid=midpoint;
24 RUN;
25 QUIT;
26 
27/* Stop the paneling */
28ods tagsets.htmlpanel event=panel(finish);
5 Code Block
PROC PRINT
Explanation :
Displays the content of the 'one' dataset as a table, with the title 'A PROC PRINT Table'.
Copied!
1title1 "A
2PROC PRINT Table";
3PROC PRINT
4DATA=one;
5RUN;
6 
6 Code Block
PROC GCHART
Explanation :
Defines dynamic by-group title and footnote. Generates a vertical bar chart from the 'one' dataset, grouped by the variable 'z'. For each group of 'z', it displays a bar for each value of 'x', where the height of the bar represents the sum of 'y'.
Copied!
1title1 'By-group title for z=#byval(z)';
2footnote1 'By-group footnote for z=#byval(z)';
3 
4PROC GCHART DATA=one;
5 BY z;
6 vbar x / sumvar=y pattid=midpoint discrete;
7RUN;
8QUIT;
7 Code Block
ODS Cleanup
Explanation :
Resets the `embedded_titles` macro variable to 'no' and closes all currently open ODS destinations, thus finalizing the creation of the output files.
Copied!
1%let embedded_titles=no;
2 
3ods _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.