Previous Page | Next Page

Writing Your Graphs to a PDF File

Examples

This section provides the following examples:

Creating a Multipage PDF File with Bookmarks and Metadata

Creating a PDF/A-1b-Compliant File that Contains Multiple Graphs Per Page

Creating a Multiple-Page PDF File Using BY-Group Processing

Creating a Multiple-Page PDF File Using the GREPLAY Procedure


Creating a Multipage PDF File with Bookmarks and Metadata

Here is an example that creates a multipage PDF file with bookmarks and metadata using RUN-group processing. Each page displays a single graph in the landscape orientation, and is set up for A4 paper with a 1 cm right, left, and bottom margin, and a 2 cm top margin. The PROCLABEL= ODS option is used to set the top-level bookmark for each category of graphs. The DESCRIPTION= option is used with each procedure to set the text of each subheading bookmark.

/* Close the LISTING destination */
ods listing close;

/* Reset the graphics options  */
goptions reset=all;

/* Open the PDF destination */
ods pdf style=seaside
   file="MyDoc.pdf"  /* Output filename */
   compress=0          /* No compression */
   /* Add metadata */
   author="J. L. Cho"
   subject="Auto makers"
   title="Car Makers by MPG and Vehicle Type"
   keywords="automobiles cars MPG sedans trucks wagons SUVs";

/* Modify the PDF page properties */
options orientation=LANDSCAPE
   papersize=A4
   leftmargin=1cm
   rightmargin=1cm
   bottommargin=1cm
   topmargin=2cm;

/* Set the top-level bookmark for the first set of graphs */
ods proclabel="Makes By MPG";

/* Create the first set of graphs */
proc gchart data=sashelp.cars;
   pie Make / name="HighMPG" other=3
      description="High-MPG"; /* Set subheading text */
      title1 "30 MPG or Better";
      where MPG_Highway >= 30;
   run;
   pie Make / name="MedMPG" other=3
      description="Average-MPG"; /* Set subheading text */
      title1 "Between 20 MPG and 29 MPG";
      where MPG_Highway < 30 and MPG_Highway >= 20;
   run;
   pie Make / name="LowMPG" other=3
      description="Low-MPG"; /* Set subheading text */
      title1 "19 MPG or less";
      where MPG_Highway < 20;
   run; 
quit;

/* Set the top-level bookmark for the second set of graphs */
ods proclabel="Makes By Type";

/* Create the second set of graphs */
proc gchart data=sashelp.cars;
   pie Make / name="Sedans" other=3
      description="Sedans"; /* Set subheading text */ 
      title1 "Sedans";
      where Type = "Sedan";
   run;
   pie Make / name="SUVs" other=3
      description="SUVs"; /* Set subheading text */
      title1 "SUVs";
      where Type="SUV";
   run;
   pie Make / name="Trucks" other=3
      description="Trucks"; /* Set subheading text */
      title1 "Trucks";
      where type="Truck";
   run; 
   pie Make / name="Wagons" other=3
      description="Wagons"; /* Set subheading text */
      title1 "Wagons";
      where type="Wagon";
   run;
   pie Make / name="Sports" other=3
      description="Sports Cars"; /* Set subheading text */ 
      title1 "Sports Cars";
      where type="Sports";
   run;  
quit;

/* Close the PDF destination */
ods pdf close;
ods listing;

/* Reset the graphics options */
goptions reset=all; 

This creates a PDF file with the bookmarks shown in the following display:

[Adobe Acrobat bookmarks pane]

The document metadata is displayed on the Description tab of the Document Properties dialog box. To open the Document Properties dialog box, type CTRL-D anywhere in the PDF viewer window or right-click in the PDF viewer window, and then select Document Properties from the pop-up menu. The following display shows the document metadata that is displayed for this example.

[Description tab of the Acrobat Document Properties dialog box]


Creating a PDF/A-1b-Compliant File that Contains Multiple Graphs Per Page

Here is an example that creates the PDF file FourVbars.pdf, which contains four graphs on one page and can be archived. The PRINTER=PDFA ODS option is used to create a PDF file that is compliant with PDF/A-1b standards. To create a standard Version 1.4 PDF file, remove the PRINTER=PDFA option from the ODS statement.

/* Close the LISTING destination */
ods listing close;

/* Set page options */
options orientation=portrait rightmargin=0.1in leftmargin=0.1in;
goptions reset=all ftext="Helvetica/bold";

/* Open PDF */
ods pdf style=printer 
    printer=pdfa         /* Create an archivable PDF */
    file="FourVbars.pdf" /* Output filename */
    startpage=never;     /* Do not insert a pagebreak after each graph */

/* Create a slide for the graphs */
goptions hsize=0 vsize=0;

proc gslide;
    title1 "1997 Quarterly U.S. Sales By State";
run;

/* Size each graph 4in x 4in */
goptions hsize=4in vsize=4in;
title1;

/* Generate the graphs */
proc gchart data=sashelp.prdsal3;
   /* Create the Q1 graph in the top-left quadrant */
   title2 "First Quarter";
   goptions horigin=0 vorigin=5;
   pie State / sumvar=Actual type=mean;
      where country="U.S.A." AND quarter=1 AND Year=1997; 
   run;

   /* Create the Q2 graph in the top-right quadrant */
   goptions horigin=4 vorigin=5;
   title2 "Second Quarter";
   pie State / sumvar=Actual type=mean;
      where country="U.S.A." AND quarter=2 AND Year=1997; 
   run;

   /* Create the Q3 graph in the bottom-left quadrant */
   title2 "Third Quarter";
   goptions horigin=0 vorigin=0;
   pie State / sumvar=Actual type=mean;
      where country="U.S.A." AND quarter=3 AND Year=1997;
   run;

   /* Create the Q4 graph in the bottom-right quadrant */
   title2 "Fourth Quarter";
   goptions horigin=4 vorigin=0;
   pie State / sumvar=Actual type=mean;
      where country="U.S.A." AND quarter=4 AND Year=1997;
   run;
quit;

/* Close PDF and reopen LISTING */
ods pdf close;
ods listing;

/* Reset the graphics options */
goptions reset=all;


Creating a Multiple-Page PDF File Using BY-Group Processing

Here is an example that uses BY-group processing to create a multiple-page PDF file that contains one graph per page in the landscape orientation.

/* Specify the landscape page orientation */
options orientation=landscape;

/* Close the LISTING destination */
ods listing close;

/* Reset the options */
goptions reset=all;

/* Open the PDF destination */
ods pdf style=statistical;

/* Create our data set by extracting 1994 data from sashelp.prdsale */
/* and sorting by product */
proc sort data=sashelp.prdsale(where=(Year=1994)) out=work.prdsale;
   by product;
run;

/* Generate the graphs */
title1 "1994 Monthly Sales By Product";
proc gchart data=work.prdsale;
   hbar month /sumvar=actual type=sum sum;
      by product;
   run;
quit;

/* Close the PDF destination */
ods pdf close;

/* Reset the graphics options */
goptions reset=all;

/* Open the LISTING destination */
ods listing;


Creating a Multiple-Page PDF File Using the GREPLAY Procedure

Here is an example that uses the GREPLAY procedure to create a PDF file that contains four graphs.

/* Specify the landscape page orientation */
options orientation=portrait;

/* Close the LISTING destination */
ods listing close;

/* Reset the options and set NODISPLAY */
goptions reset=all nodisplay;

/* Open the PDF destination */
ods pdf style=statistical file="Mygraph.pdf";

/* Create our data set by extracting 1994 data from sashelp.prdsale */
/* and sorting by quarter */
proc sort data=sashelp.prdsale(where=(Year=1994)) out=work.prdsale;
   by quarter;
run;

/* Delete the old GRSEGs */
proc greplay igout=work.gseg nofs;
   delete _all_;
run;

/* Generate the graphs */
proc gchart data=work.prdsale;
   vbar product /sumvar=actual discrete type=mean mean;
      title1 "1994 Q1 Average Sales By Product";
      where quarter=1;
   run;

      title1 "1994 Q2 Average Sales By Product";
      where quarter=2;
   run;

      title1 "1994 Q3 Average Sales By Product";
      where quarter=3;
   run;

      title1 "1994 Q4 Average Sales By Product";
      where quarter=4;
   run;
quit; 

/* Replay the graphs to the PDF file */
goptions display;
proc greplay igout=work.gseg nofs;
   replay _all_;
run;
quit;

/* Close the PDF destination */
ods pdf close;

/* Reset the graphics options */
goptions reset=all;

/* Open the LISTING destination */
ods listing;

Previous Page | Next Page | Top of Page