Example 9: Combining Graphs and Reports in a Web Page

Features:
AXIS statement options:
LENGTH=
MINOR=
ORDER=
VALUE=

BY statement

GOPTIONS statement options:
BORDER
DEVICE=
TRANSPARENCY
LEGEND statement options:
LABEL=
SHAPE=
ODS HTML statement options:
BODY=
CONTENTS=
FRAME=
PATH=
NOGTITLE

OPTIONS statement option: NOBYLINE

TITLE statement option: #BYVAL

Sample library member: GONCGRW1
This example generates several graphs of sales data that can be accessed from a single Web page. The graphs are two bar charts of summary sales data and three pie charts that break the data down by site. Each bar chart and an accompanying report is stored in a separate body file.
The three pie charts are generated with BY-group processing and are stored in one body file. The program suppresses the default BY lines and instead includes the BY variable value in the title for each chart. The SAS/GRAPH titles are displayed in the HTML output instead of in the graphics output.
The Web page contains two frames, one that displays a Table of Contents for all the graphs, and one that serves as the display area. Links to each piece of output appear in the table of contents, which is displayed in the left frame. Initially the frame file displays the first body file, which contains a bar chart and a report, as shown in the following figure.
Browser View of Bar Chart and Quarterly Sales Report
output from goncgrw1.sas
Notice that the chart title is displayed outside the graph as part of the HTML file. Select the link to Total Department Sales to display the second bar chart, as shown in the following figure.
Browser View of Bar Chart and Department Sales Report
output from goncgrw1.sas
Selecting any link for Department Sales displays the corresponding pie chart as shown in the following figure. Because the pie charts are stored in one file, you can easily see all three by scrolling through the file.
Browser View of Pie Charts of Site Sales
output from goncgrw1.sas

Program

goptions reset=all border;
data totals;
   length Dept $ 7 Site $ 8;
   input Dept Site Quarter Sales;
   datalines;

Repairs Sydney  1 5592.82
Repairs Atlanta 1 9210.21
Tools   Sydney  1 1775.74
Tools   Atlanta 1 2424.19
Tools   Paris   1 5914.25
Parts   Atlanta 2 11595.07
Parts   Paris   2 9558.29
Repairs Sydney  2 5505.31
Repairs Paris   2 7538.56
Tools   Atlanta 2 1903.99
Tools   Paris   2 7868.34
Parts   Sydney  3 8437.96
Parts   Paris   3 6789.85
Tools   Atlanta 3 3048.52
Tools   Paris   3 9017.96
Parts   Sydney  4 6065.57
Parts   Atlanta 4 9388.51
Parts   Paris   4 8509.08
Repairs Atlanta 4 2088.30
Repairs Paris   4 5530.37
;
ods html frame="sales_frame.html"
   contents="sales_contents.html"
   body="sales_body1.html"
    nogtitle;
title1 "Total Sales By Quarter";
footnote j=r  "salesqtr ";
axis1 order=(0 to 60000 by 20000)
      minor=(number=1)
      label=none;
axis2 label=none length=70pct
      value=("1Q" "2Q" "3Q" "4Q");
legend1 label=none shape=bar(4,4);
proc gchart data=totals;
   format sales dollar8.;
   vbar3d quarter / discrete
                    sumvar=sales
                    shape=cylinder
                    subgroup=site
                    cframe=grayaa
                    caxis=black
                    width=12
                    space=4
                    legend=legend1
                    maxis=axis2
                    raxis=axis1
                    des="Total Quarterly Sales"
                    name="salesqtr";
run;
quit;
proc sort data=totals out=qtrsort;
   by quarter site;
run;
quit;
footnote1;
options nobyline;
title1 "Sales for Quarter #byval(quarter)";
proc report data=qtrsort nowindows;
  by quarter;
  column quarter site dept sales;
  define quarter / noprint group;
  define site    / display group;
  define dept    / display group;
  define sales   / display sum format=dollar8.;
  compute after quarter;
          site="Total";
  endcomp;
  break after site    / summarize style=rowheader;
  break after quarter / summarize style=rowheader;
run;
quit;
ods html body="sales_body2.html";
title1 "Total Sales By Department";
footnote1 j=r  "salesdep ";
axis1 label=none
      minor=(number=1);
      order=(0 to 100000 by 20000);
axis2 label=none length=70pct;
proc gchart data=totals;
   format sales dollar8.;
   vbar3d dept / shape=cylinder
                 subgroup=site
                 cframe=grayaa
                 width=12
                 space=4
                 sumvar=sales
                 legend=legend1
                 maxis=axis2
                 raxis=axis1
                 caxis=black
                 des="Total Department Sales"
                 name="salesdep";
run;
quit;
proc sort data=totals out=deptsort;
   by dept site;
run;
quit;
footnote1;
title1 "Sales for #byval(dept)";
proc report data=deptsort nowindows;
  by dept;
  column dept site quarter sales;
  define dept    / noprint group;
  define site    / display group;
  define quarter / display group;
  define sales   / display sum format=dollar8.;
  compute after dept;
          site="Total";
  endcomp;
  break after site / summarize style=rowheader;
  break after dept / summarize style=rowheader;
run;
quit;
ods html body="sales_body3.html"  gtitle;
proc sort data=totals out=sitesort;
   by site;
run;
quit;
title1 "Departmental Sales for #byval(site)";
footnote j=r "salespie ";
proc gchart data=sitesort;
     format sales dollar8.;
     by site;
     pie3d dept / noheading
                  coutline=black
                  sumvar=sales
                  des="Department Sales"
                  name="salespie";
run;
quit;
ods html close;

Program Description

By default the ODS HTML statement to generate the graphics output as PNG files. The BORDER option is used so that the border around the graphics output area is compatible with the borders that are created for non-graphics output.Set the graphics environment.
goptions reset=all border;
Create the data set TOTALS. The data set contains quarterly sales data for three manufacturing sites for one year.
data totals;
   length Dept $ 7 Site $ 8;
   input Dept Site Quarter Sales;
   datalines;

Repairs Sydney  1 5592.82
Repairs Atlanta 1 9210.21
Tools   Sydney  1 1775.74
Tools   Atlanta 1 2424.19
Tools   Paris   1 5914.25
Parts   Atlanta 2 11595.07
Parts   Paris   2 9558.29
Repairs Sydney  2 5505.31
Repairs Paris   2 7538.56
Tools   Atlanta 2 1903.99
Tools   Paris   2 7868.34
Parts   Sydney  3 8437.96
Parts   Paris   3 6789.85
Tools   Atlanta 3 3048.52
Tools   Paris   3 9017.96
Parts   Sydney  4 6065.57
Parts   Atlanta 4 9388.51
Parts   Paris   4 8509.08
Repairs Atlanta 4 2088.30
Repairs Paris   4 5530.37
;
Set the ODS HTML destination for file handling options. The FRAME= option names the HTML file that integrates the contents and body files. The CONTENTS= option names the HTML file that contains the table of contents to the HTML procedure output. The BODY= option names the file for storing the HTML output. The contents file links to each of the body files written to the HTML destination. The NOGTITLE option suppresses the graphics titles from the SAS/GRAPH output and displays them through the HTML page.
ods html frame="sales_frame.html"
   contents="sales_contents.html"
   body="sales_body1.html"
    nogtitle;
Define title and footnote.
title1 "Total Sales By Quarter";
footnote j=r  "salesqtr ";
Define axis characteristics for the first bar chart. In AXIS2, the LENGTH= option specifies the length of the midpoint axis.
axis1 order=(0 to 60000 by 20000)
      minor=(number=1)
      label=none;
axis2 label=none length=70pct
      value=("1Q" "2Q" "3Q" "4Q");
Suppress the legend label and define the size of the legend values.
legend1 label=none shape=bar(4,4);
Generate the vertical bar chart of quarterly sales. The NAME= option specifies the name of the catalog entry.
proc gchart data=totals;
   format sales dollar8.;
   vbar3d quarter / discrete
                    sumvar=sales
                    shape=cylinder
                    subgroup=site
                    cframe=grayaa
                    caxis=black
                    width=12
                    space=4
                    legend=legend1
                    maxis=axis2
                    raxis=axis1
                    des="Total Quarterly Sales"
                    name="salesqtr";
run;
quit;
Sort the data set for the report of quarterly sales. The data must be sorted in order of the BY variable before running PROC REPORT with BY-group processing.
proc sort data=totals out=qtrsort;
   by quarter site;
run;
quit;
Reset the footnote and suppress the BY line. We suppress the BY line because otherwise #BYVAL inserts the value of the BY variable into the title of each report.
footnote1;
options nobyline;
Generate a report of quarterly sales. Because the HTML body file that references the GCHART procedure output is still open, the report is stored in that file. The chart and report are shown in Browser View of Bar Chart and Quarterly Sales Report.
title1 "Sales for Quarter #byval(quarter)";
proc report data=qtrsort nowindows;
  by quarter;
  column quarter site dept sales;
  define quarter / noprint group;
  define site    / display group;
  define dept    / display group;
  define sales   / display sum format=dollar8.;
  compute after quarter;
          site="Total";
  endcomp;
  break after site    / summarize style=rowheader;
  break after quarter / summarize style=rowheader;
run;
quit;
Assign a new body file for the second bar chart and report. Assigning a new body file closes SALES_BODY1.HTML. The contents and frame files, which remain open, contains links to all body files.
ods html body="sales_body2.html";
Define title and footnote for second bar chart.
title1 "Total Sales By Department";
footnote1 j=r  "salesdep ";
Define axis characteristics. These axis statements replace the ones defined earlier. As before, the LENGTH= option defines the length of the midpoint axis.
axis1 label=none
      minor=(number=1);
      order=(0 to 100000 by 20000);
axis2 label=none length=70pct;
Generate the vertical bar chart of departmental sales.
proc gchart data=totals;
   format sales dollar8.;
   vbar3d dept / shape=cylinder
                 subgroup=site
                 cframe=grayaa
                 width=12
                 space=4
                 sumvar=sales
                 legend=legend1
                 maxis=axis2
                 raxis=axis1
                 caxis=black
                 des="Total Department Sales"
                 name="salesdep";
run;
quit;
Sort the data set for the report of department sales. The data must be sorted in order of the BY variable before running PROC REPORT with BY-group processing.
proc sort data=totals out=deptsort;
   by dept site;
run;
quit;
Reset the footnote, define a report title, and generate the report of department sales. #BYVAL inserts the value of the BY variable into the title of each report. The chart and report are shown in Browser View of Bar Chart and Quarterly Sales Report.
footnote1;
title1 "Sales for #byval(dept)";
proc report data=deptsort nowindows;
  by dept;
  column dept site quarter sales;
  define dept    / noprint group;
  define site    / display group;
  define quarter / display group;
  define sales   / display sum format=dollar8.;
  compute after dept;
          site="Total";
  endcomp;
  break after site / summarize style=rowheader;
  break after dept / summarize style=rowheader;
run;
quit;
Assign a new body file for the pie charts. Assigning a new file as the body file closes SALES_BODY2.HTML. The contents and frame files remain open. GTITLE displays the titles in the graph.
ods html body="sales_body3.html"  gtitle;
Sort data set in order of the BY variable before running the GCHART procedure with BY-group processing.
proc sort data=totals out=sitesort;
   by site;
run;
quit;
Define title and footnote. #BYVAL inserts the value of the BY variable SITE into the title for each output.
title1 "Departmental Sales for #byval(site)";
footnote j=r "salespie ";
Generate a pie chart for each site. All the procedure output is stored in one body file. Because BY-group processing generates multiple graphs from one PIE3D statement, the name assigned by the NAME= option is incremented to provide a unique name for each piece of output.
proc gchart data=sitesort;
     format sales dollar8.;
     by site;
     pie3d dept / noheading
                  coutline=black
                  sumvar=sales
                  des="Department Sales"
                  name="salespie";
run;
quit;
Close the ODS HTML destination. If you do not close the destination, then you are not able to view the HTML file specified by the FRAME option until you close your SAS session.
ods html close;