Sample Programs: Metaview Applet


The following sample programs use DEVICE=JAVAMETA to generate metcodes to be displayed by the Metaview applet:

  • Metacode Output with HTML from ODS on page 478

  • Producing a Web Presentation with the META2HTM Macro on page 481

  • Embedding Multiple Instances of the Metaview Applet on the Same HTML Page with META2HTM on page 483.

Metacode Output with HTML from ODS

The following sample program uses ODS to create an HTML file, and GOPTIONS DEVICE=JAVAMETA with two instances of PROC GCHART to create graphical output in the form of metacodes. Because both instances of PROC GCHART contain a BY statement, the HTML file created by ODS contains multiple invocations of the applet ”one invocation for each value of the BY statement for each procedure (eight invocations in all). The metacodes produced by PROC GCHART are passed to the applet as a parameter.

When you use DEVICE=JAVAMETA with ODS, only one graph can be passed to an instance of the Metaview applet at a time. ODS generates a separate invocation of the Metaview applet for each SAS/GRAPH procedure that it runs. And, if a procedure includes BY GROUP processing, then it generates another separate invocation of the Metaview applet for each BY- group chart. In sum, Metaview applet presentations generated by ODS never contain a slider page control or drop-down list graph control to allow a user to select which graph is to be displayed. Although an HTML page generated by ODS can contain multiple instances of the Metaview applet, each instance can display one picture only, and a user must scroll the HTML page to see all the pictures.

Each GCHART procedure in this example includes a BY statement to display the results of each of the four quarters of the year. Consequently, ODS generates eight separate invocations of the Metaview applet, only the first of which is shown here. A user would have to scroll the page in the browser to see all four quarters displayed. Notice the slider control at the bottom of the image. Because the image is displayed by the Metaview, the run-time option is available to the user to control the magnification of the chart.

click to expand

SAS Code

The following is the complete SAS code to generate a Web presentation. You should notice the following:

  • PROC GREPLAY is used to delete the GSEGS that are created. This is not necessary, but otherwise SAS creates new GSEGS each time the procedure is run, rather than overwriting the old ones.

  • The HTML file is created using ODS HTML.

  • The FILE= option of the ODS statement specifies the path and file name of the HTML file to be created. If you run this example, then change the value of the option to something that makes sense for you.

  • The statement GOPTIONS DEVICE=JAVAMETA causes PROC GCHART to produce metacodes which are embedded in the HTML file produced by ODS and passed to the Metaview applet as parameters.

 data prdsummary;     input Year Quarter Country . Product . Actual dollar10.2;     label Actual = 'Actual Sales';     format Actual dollar11.;     datalines;  1993 1 CANADA  BED   ,337.00  1993 1 CANADA  CHAIR ,115.00  1993 1 CANADA  DESK  ,644.00  1993 1 GERMANY BED   ,026.00  1993 1 GERMANY CHAIR ,276.00  1993 1 GERMANY DESK  ,330.00  1993 2 CANADA  BED   ,437.00  1993 2 CANADA  CHAIR ,115.00  1993 2 CANADA  DESK  ,654.00  1993 2 GERMANY BED   ,026.00  1993 2 GERMANY CHAIR ,276.00  1993 2 GERMANY DESK  ,320.00  1993 3 CANADA  BED   ,337.00  1993 3 CANADA  CHAIR ,145.00  1993 3 CANADA  DESK  ,614.00  1993 3 GERMANY BED   ,026.00  1993 3 GERMANY CHAIR ,276.00  1993 3 GERMANY DESK  ,340.00  1993 4 CANADA  BED   ,337.00  1993 4 CANADA  CHAIR ,115.00  1993 4 CANADA  DESK  ,646.00  1993 4 GERMANY BED   ,026.00  1993 4 GERMANY CHAIR ,276.00  1993 4 GERMANY DESK  ,350.00  1994 1 CANADA  BED   ,327.00  1994 1 CANADA  CHAIR ,345.00  1994 1 CANADA  DESK  ,624.00  1994 1 GERMANY BED   ,026.00  1994 1 GERMANY CHAIR ,276.00  1994 1 GERMANY DESK  ,340.00  1994 2 CANADA  BED   ,356.00  1994 2 CANADA  CHAIR ,115.00  1994 2 CANADA  DESK  ,623.00  1994 2 GERMANY BED   ,026.00  1994 2 GERMANY CHAIR ,276.00  1994 2 GERMANY DESK  ,321.00  1994 3 CANADA  BED   ,321.00  1994 3 CANADA  CHAIR ,115.00  1994 3 CANADA  DESK  ,658.00  1994 3 GERMANY BED   ,026.00  1994 3 GERMANY CHAIR ,276.00  1994 3 GERMANY DESK  ,398.00  1994 4 CANADA  BED   ,357.00  1994 4 CANADA  CHAIR ,166.00  1994 4 CANADA  DESK  ,662.00  1994 4 GERMANY BED   ,026.00  1994 4 GERMANY CHAIR ,246.00  1994 4 GERMANY DESK  ,329.00  ;   /* Delete previously created gsegs before creating new ones. */  proc greplay igout=work.gseg nofs;     delete _all_;     /* Could also specify: delete gchart, gchart1, etc. */  run; quit;  ods html file='u:\public\Web_output\ods_javameta_exp.htm';  goptions reset=all device=javameta           border           ftext="Helvetica" ftitle="Helvetica";  title1 '1993 Sales';  proc gchart data=prdsummary(where=(year=1993));     hbar3d country / sumvar=actual subgroup=product sum     shape=hexagon caxis=black cframe=blue;     by quarter;  run;  quit;  title1 '1994 Sales';  proc gchart data=prdsummary(where=(year=1994));     hbar3d country / sumvar=actual subgroup=product sum     shape=hexagon caxis=black cframe=blue;     by quarter;  run;  quit;  ods html close; 

Producing a Web Presentation with the META2HTM Macro

The following sample program uses the META2HTM macro to create an HTML file, and GOPTIONS DEVICE=JAVAMETA with PROC GCHART to create graphical output in the form of metacodes. When you use the META2HTM macro, the metacodes produced by a SAS/GRAPH procedure are embedded in the HTML file. This enables you to display multiple charts with one invocation of the Metaview applet.

The sample codes contains one invocation of PROC GCHART with a BY statement to produce charts for each quarter of the year. However, each of the four charts is displayed in sequence on a single output area of the same HTML page (no scrolling is necessary). The Metaview applet provides a slider control, which allows a user to select which quarter to display.

click to expand

SAS Code

The following is the complete SAS code to generate a web presentation. You should notice the following:

  • The statement FILENAME _WEBOUT specifies the name of the HTML file to be produced by the META2HTM macro. When GOPTIONS DEVICE=JAVAMETA, the output of a SAS/GRAPH procedure is directed to the file specified by _WEBOUT. Because the META2HTM macro produces an HTML file, the metacodes produced by the SAS/GRAPH procedure are embedded in the HTML file. If you run this sample, change the value of _WEBOUT to something that makes sense for you.

  • The META2HTM macro is invoked twice ”once before the SAS/GRAPH procedure in order to specify parameters for the procedure, and a second time after the procedure to close the HTML file created.

 data prdsummary;     input Year Quarter Country . Product . Actual dollar10.2;     label Actual = 'Actual Sales';     format Actual dollar11.;     datalines;  1993 1 CANADA  BED   ,337.00  1993 1 CANADA  CHAIR ,115.00  1993 1 CANADA  DESK  ,644.00  1993 1 GERMANY BED   ,026.00  1993 1 GERMANY CHAIR ,276.00  ...more data lines...  1994 4 CANADA  CHAIR ,166.00  1994 4 CANADA  DESK  ,662.00  1994 4 GERMANY BED   ,026.00  1994 4 GERMANY CHAIR ,246.00  1994 4 GERMANY DESK  ,329.00  ;  run;  /* When goptions device=javameta, the procedure output goes to _webout. */  /* In this case the metacodes are embedded in the html file.  */  filename _webout 'u:\public\Web_output\meta2htm_javameta_sample1.htm';  %meta2htm(capture=on,           htmlfref=_webout,           openmode=replace,           /* Specify codebase if metafile.zip is not in same */           /* directory as the html file. */           codebase=http://web_server_name/sasweb/graph           archive=metafile.zip,           slidectl=n,           /* don't advance pictures automatically like a slideshow */           hspace=1,           vspace=2);  goptions reset=all device=javameta           border           ftext="Helvetica" ftitle="Helvetica";  title1 '1993 Sales';  proc gchart data=prdsummary(where=(year=1993));     hbar3d country / sumvar=actual subgroup=product sum     shape=hexagon caxis=black cframe=blue;     by quarter;  run;  quit;  %meta2htm(capture=off,            htmlfref=_webout,            openmode=append);  quit; 

Embedding Multiple Instances of the Metaview Applet on the Same HTML Page with META2HTM

Using the META2HTM macro, you can embed multiple instances of the Metaview applet in a single HTML page, and for each instance you can display the output of a different SAS/GRAPH procedure, as illustrated in the current example.

The sample code contains two invocations of PROC GCHART, each invocation with a BY statement, to produce a total of eight charts (four quarters per year times two years ). The Metaview applet is invoked twice, and each time provides a slider control, which enables a user to select which quarter to display for that particular year.

click to expand
click to expand

SAS Code

The following is the complete SAS code to generate a Web presentation. You should notice the following:

  • The statement FILENAME _WEBOUT specifies the name of the metacode file to be produced by PROC GCHART. When GOPTIONS DEVICE=JAVAMETA, the output of a SAS/GRAPH procedure is directed to the file specified by _WEBOUT. If you run this sample, change the value of _WEBOUT to something that makes sense for you.

  • When the META2HTM macro is invoked prior to the second occurrence of PROC GCHART, it is invoked with the parameter OPENMODE=APPEND, so that the second invocation of the Metaview applet is included in the same HTML file as the first one.

 data prdsummary;     input Year Quarter Country . Product . Actual dollar10.2;     label Actual = 'Actual Sales';     format Actual dollar11.;     datalines;  1993 1 CANADA  BED   ,337.00  1993 1 CANADA  CHAIR ,115.00  1993 1 CANADA  DESK  ,644.00  1993 1 GERMANY BED   ,026.00  1993 2 GERMANY BED   ,026.00  ...more data lines...  1994 4 CANADA  CHAIR ,166.00  1994 4 CANADA  DESK  ,662.00  1994 4 GERMANY BED   ,026.00  1994 4 GERMANY CHAIR ,246.00  1994 4 GERMANY DESK  ,329.00  ;   /* When goptions device=javameta, the output of the procedure */   /* goes to _webout. */   /* In this case, the metcodes output is embedded in the html */   /* file produced by meta2htm. */  filename _webout 'u:\public\Web_output\meta2htm_javameta_sample2.htm';  %meta2htm(capture=on,            htmlfref=_webout,            openmode=replace,            /* Specify codebase if metafile.zip is not in same directory as the */            /* html file. */            codebase=http://web_server_name/sasweb/graph            archive=metafile.zip,            pagepart=head,            slidectl=n,            /* don't advance pictures automatically like a slideshow */            hspace=1,            vspace=2);  goptions reset=all device=javameta           border           ftext="Helvetica" ftitle="Helvetica";  title1 '1993 Sales';  proc gchart data=prdsummary(where=(year=1993));     hbar3d country / sumvar=actual subgroup=product sum     shape=hexagon caxis=black cframe=blue;     by quarter;  run;  quit;  %meta2htm(capture=off,            htmlfref=_webout,            openmode=append,            pagepart=body);  %meta2htm(capture=on,            htmlfref=_webout,            archive=metafile.zip,            openmode=append,            slidectl=n,            /* don't advance pictures automatically like a slideshow */            pagepart=body);  title1 '1994 Sales';  proc gchart data=prdsummary(where=(year=1994));     hbar3d country / sumvar=actual subgroup=product sum     shape=hexagon caxis=black cframe=blue;     by quarter;  run;  quit;  %meta2htm(capture=off,            htmlfref=_webout,                    openmode=append,            pagepart=foot);  quit; 



SAS.GRAPH 9.1 Reference, Volumes I and II
SAS.GRAPH 9.1 Reference, Volumes I and II
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 342

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net