SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Creating Drill-Down Graphs in HTML
Complete Program and Output


The complete program that you have developed is shown below. Its linked HTML output appears on the following pages. Since this program is complete and can be used as a template, feel free to copy and edit the code. Be sure to edit the ODS HTML PATH= string (shown in bold red) to conform to your system's file structure, and add any options, suboptions, or statements necessary in your operating environment.

Tip:

To copy this program directly into your SAS session, you can issue the following command from the Program Editor window:

copy sashelp.oltutor.m9pgm.source

Here is the complete program:
     data work.saletrnd;
        set finance.prdsal2;

  /* create variables to hold HREF address strings */

     length PriDrill $ 40 SecDrill $ 40;

  /* define the HTML links for the primary chart */

     if year=1995 then pridrill='HREF="sales95.html"';
     if year=1996 then pridrill='HREF="sales96.html"';
     if year=1997 then pridrill='HREF="sales97.html"';
     if year=1998 then pridrill='HREF="sales98.html"';

  /* define the HTML links for the secondary charts */

     if quarter=1 then secdrill='HREF="#salesq1"';
     if quarter=2 then secdrill='HREF="#salesq2"';
     if quarter=3 then secdrill='HREF="#salesq3"';
     if quarter=4 then secdrill='HREF="#salesq4"';

  /* fix the format of the chart variable ACTUAL */

        format actual dollar10.0;

  /* switch to HTML output...set the directory for GIF & */
  /* HTML output and specify the name of the HTML file   */

     run;
     ods listing close;
     ods html path='c:\data\sales\reports'
         body='totsales.html';

  /* switch to GIF output for images...set image size */

     goptions device=gif xpixels=480 ypixels=360;

  /* set title of the primary chart */

     title 'Total Sales by Year';

  /* create a bar chart of sales by year... */
  /* assign the HTML links held by PriDrill */

     proc gchart data=work.saletrnd;
        vbar year / subgroup=prodtype discrete
             sumvar=actual html=pridrill;
     run;

  /* specify the HTML file name of the secondary chart... */
  /* set the title and create a bar chart where YEAR=1995 */

     ods html body='sales95.html';
     title 'Sales for 1995 by Quarter';
     proc gchart data=work.saletrnd;
        vbar quarter / sumvar=actual subgroup=product 
             discrete html=secdrill;
        where year=1995;
     run;

  /* create a named anchor in the current HTML page...set a */
  /* title and create a table where YEAR=1995 & QUARTER=1-4 */

     ods html anchor='salesq1';
     title '1st Quarter 1995 Sales by Country';
     proc tabulate data=work.saletrnd format=dollar10.0;
        class country product;
        var actual;
        table (country all)*(product all), sum*actual;
        where year=1995 and quarter=1;
     run;

     ods html anchor='salesq2';
     title '2nd Quarter 1995 Sales by Country';
     proc tabulate data=work.saletrnd format=dollar10.0;
        class country product;
        var actual;
        table (country all)*(product all), sum*actual;
        where year=1995 and quarter=2;
     run;

     ods html anchor='salesq3';
     title '3rd Quarter 1995 Sales by Country';
     proc tabulate data=work.saletrnd format=dollar10.0;
        class country product;
        var actual;
        table (country all)*(product all), sum*actual;
        where year=1995 and quarter=3;
     run;

     ods html anchor='salesq4';
     title '4th Quarter 1995 Sales by Country';
     proc tabulate data=work.saletrnd format=dollar10.0;
        class country product;
        var actual;
        table (country all)*(product all), sum*actual;
        where year=1995 and quarter=4;
     run;

  /* specify the HTML file name of the secondary chart... */
  /* set the title and create a bar chart where YEAR=1996 */

     ods html body='sales96.html';
     title 'Sales for 1996 by Quarter';
     proc gchart data=work.saletrnd;
        vbar quarter / sumvar=actual subgroup=product
             discrete html=secdrill;
        where year=1996;
     run;

  /* create an anchor in the current HTML page...set a      */
  /* title and create a table where YEAR=1996 & QUARTER=1-4 */

     ods html anchor='salesq1';
     title '1st Quarter 1996 Sales by Country';
     proc tabulate data=work.saletrnd format=dollar10.0;
        class country product;
        var actual;
        table (country all)*(product all), sum*actual;
        where year=1996 and quarter=1;
     run;

     ods html anchor='salesq2';
     title '2nd Quarter 1996 Sales by Country';
     proc tabulate data=work.saletrnd format=dollar10.0;
        class country product;
        var actual;
        table (country all)*(product all), sum*actual;
        where year=1996 and quarter=2;
     run;

     ods html anchor='salesq3';
     title '3rd Quarter 1996 Sales by Country';
     proc tabulate data=work.saletrnd format=dollar10.0;
        class country product;
        var actual;
        table (country all)*(product all), sum*actual;
        where year=1996 and quarter=3;
     run;

     ods html anchor='salesq4';
     title '4th Quarter 1996 Sales by Country';
     proc tabulate data=work.saletrnd format=dollar10.0;
        class country product;
        var actual;
        table (country all)*(product all), sum*actual;
        where year=1996 and quarter=4;
     run;

  /* specify the HTML file name of the secondary chart... */
  /* set the title and create a bar chart where YEAR=1997 */

     ods html body='sales97.html';
     title 'Sales for 1997 by Quarter';
     proc gchart data=work.saletrnd;
        vbar quarter / sumvar=actual subgroup=product
             discrete html=secdrill;
        where year=1997;
     run;

  /* create a named anchor in the current HTML page...set a */
  /* title and create a table where YEAR=1997 & QUARTER=1-4 */

     ods html anchor='salesq1';
     title '1st Quarter 1997 Sales by Country';
     proc tabulate data=work.saletrnd format=dollar10.0;
        class country product;
        var actual;
        table (country all)*(product all), sum*actual;
        where year=1997 and quarter=1;
     run;

     ods html anchor='salesq2';
     title '2nd Quarter 1997 Sales by Country';
     proc tabulate data=work.saletrnd format=dollar10.0;
        class country product;
        var actual;
        table (country all)*(product all), sum*actual;
        where year=1997 and quarter=2;
     run;

     ods html anchor='salesq3';
     title '3rd Quarter 1997 Sales by Country';
     proc tabulate data=work.saletrnd format=dollar10.0;
        class country product;
        var actual;
        table (country all)*(product all), sum*actual;
        where year=1997 and quarter=3;
     run;

     ods html anchor='salesq4';
     title '4th Quarter 1997 Sales by Country';
     proc tabulate data=work.saletrnd format=dollar10.0;
        class country product;
        var actual;
        table (country all)*(product all), sum*actual;
        where year=1997 and quarter=4;
     run;

  /* specify the HTML file name of the secondary chart... */
  /* set the title and create a bar chart where YEAR=1998 */

     ods html body='sales98.html';
     title 'Sales for 1998 by Quarter';
     proc gchart data=work.saletrnd;
        vbar quarter / sumvar=actual subgroup=product
             discrete html=secdrill;
        where year=1998;
     run;

  /* create a named anchor in the current HTML page...set a */
  /* title and create a table where YEAR=1998 & QUARTER=1-4 */

     ods html anchor='salesq1';
     title '1st Quarter 1998 Sales by Country';
     proc tabulate data=work.saletrnd format=dollar10.0;
        class country product;
        var actual;
        table (country all)*(product all), sum*actual;
        where year=1998 and quarter=1;
     run;

     ods html anchor='salesq2';
     title '2nd Quarter 1998 Sales by Country';
     proc tabulate data=work.saletrnd format=dollar10.0;
        class country product;
        var actual;
        table (country all)*(product all), sum*actual;
        where year=1998 and quarter=2;
     run;

     ods html anchor='salesq3';
     title '3rd Quarter 1998 Sales by Country';
     proc tabulate data=work.saletrnd format=dollar10.0;
        class country product;
        var actual;
        table (country all)*(product all), sum*actual;
        where year=1998 and quarter=3;
     run;

     ods html anchor='salesq4';
     title '4th Quarter 1998 Sales by Country';
     proc tabulate data=work.saletrnd format=dollar10.0;
        class country product;
        var actual;
        table (country all)*(product all), sum*actual;
        where year=1998 and quarter=4;
     run;

  /* switch back to listing output */

     quit;
     ods html close;
     ods listing;

  back||next


Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.

Terms of Use & Legal Information | Privacy Statement