ODS PDF destination in SAS 9.4: Come take a look under the hood!

2

ProblemSolversIf you have programmed with SAS in the last 15 years, you have probably had a reason to share your SAS results in PDF format. The ODS PDF destination, much like a well-designed car, has evolved over the years, offering progressively nicer features like security, enhanced image formatting and embedded fonts. I think you’re going to like what SAS 9.4 has to offer!

Let’s discuss three key SAS 9.4 improvements to this beloved, reliable and top rated ODS destination:

  • Pearl default style
  • ODS LAYOUT statement
  • ODSLIST and ODSTEXT procedures

ODS PDF’s new default style: Not just a pretty paint color.

Just like car manufacturers, the ODS developers have improved the “look and feel” of the PDF destination in SAS 9.4 by updating the default style. Styles.Pearl, the new default style for ODS PDF and ODS PRINTER,  is designed with a more modern feel. The headers are no longer shaded, the borders are lighter and we think you’ll agree the results are much more appealing. Here’s a screen shot showing sample PROC PRINT results comparing the new default style, styles.Pearl, with the earlier default, styles.Printer:

Illustration showing differences in SAS 9.4 default ODS Styles.PEARL and previous default Styles.PRINTER

ODS LAYOUT: Production status with robust documentation

The ODS LAYOUT feature, which allows the precise placement of SAS output on a PDF page, was introduced in SAS 9.2. However, it held so much power and required so many feature improvements, it was released in preproduction status. Since that time the SAS programming community has offered feedback on its performance and features, leading to the SAS 9.4 release where the destination is offered with two distinct models: GRIDDED and ABSOLUTE, both of which offer robust “owner’s manuals”.

We think the ABSOLUTE model will be the most popular. You can use it to place tables and images side by side, stack them top to bottom and even overlay output in your PDF files, and works to create output placed on a single PDF page.  The GRIDDED model is more useful when using BY-group data and/or creating multi page output.

The ABSOLUTE LAYOUT syntax uses a pair of ODS LAYOUT statements (ODS LAYOUT START and ODS LAYOUT END) to define the area on the page to which you will write ODS REGIONs.  ODS REGION statements define the location and size of regions to which you will write tables, text or images. Both statements use the X= argument to define the horizontal “start” position, and Y= to define the vertical start position of your output. If you do not use either of these, the output starts in the upper left corner (0,0). Height= and Width= arguments can be used on both statements to control the size of the layouts and regions.

Here is sample code for defining a sleek layout page within your ODS PDF destination:

  • Create a PDF file with FILE=, turn off the bookmark/table of contents with NOTOC, and with NOGTITLE make all Graph titles part of the PDF file, instead of embedding them in the Graph images.
    ods pdf file="file.pdf" notoc nogtitle ;
  • Define a LAYOUT that is 7.25 inches high and 10.5 inches wide.  The keyword ABSOLUTE is not necessary as it is implied if neither the COLUMNS= nor the ROWS= option is used. Previously we have set the system option ORIENTATION= to LANDSCAPE on an OPTIONS statement and set a Title and Footnote, whose text will be placed outside the layout.
    ods layout start height=7.25in width=10.5in ;
  • Define the first REGION. The region is placed inside my layout, starting .75 inch from my top margin (y=.75in) and one inch from my left margin (x=1in). This region is allocated 3.5inches of space across my page (width=3.5in).
    ods region x=1in y=.75in width=3.5in ;

The ODS LAYOUT and REGION statements used above are part of Sample 55808.  We’ll use the full code to generate the following output from SAS 9.4, and I’ll explain how to assemble all the pieces using other new features in SAS 9.4:

SAS 9.4 ODS output using ODS LAYOUT statement

PROC ODSTEXT: easily insert paragraphs of text

The ODSTEXT procedure helps us format paragraph text that would previously have been written with DATA _null_ / FILE PRINT logic or ODS <destination> TEXT= syntax. However, neither of these methods allow for elegant style control and line spacing, nor do either of those strategies integrate well with the table of contents.  Now using PROC ODSTEXT, we can format paragraphs of text (or just single words if preferred!), with ease.

Here’s the first PROC ODSTEXT code used in our screen shot shown above:

  
proc odstext;
    p "The ODSTEXT procedure offers a powerful tool for inserting paragraph style text into your ODS destinations. "  / style=systemtitle;
    p  "The ODSTEXT procedure allows us to: format text with style control offered with the statement option style=,  use data sets, and add bullets."  / style=systemtitle;
    p '  ';
    p "A close sibling is PROC ODSLIST, used to generate the following bulleted list of improved ODS PDF features:" /  style=header;
run;

Here are the results:

PROC ODSTEXT output showing three sizes and

PROC ODSLIST: easily create bulleted lists

Closely related to the ODSTEXT procedure is PROC ODSLIST, which allows us to create nicely formatted, indented and bulleted lists from a SAS dataset. Here’s an example:

 proc odslist data=features;
   item feature /style={bullet="disc"};
   end;
 run;

Here are the results:

PROC ODSLIST output
There’s an added bonus in SAS 9.4: the ODSLIST and ODSTEXT procedures can be used in ANY of the non-LISTING ODS destinations.  Try them out in ODS POWERPOINT and ODS RTF too!

Adding the bar chart to our layout

The image in our PDF file is created with the PROC SGPLOT and highlights a feature new in SAS 9.4, the SYMBOLCHAR statement.  The data and program are described in Sample 54315 and a recent Problem Solvers blog. The key to sizing and inserting the output in the upper right corner of our PDF file is specifying the following ODS REGION statement and the ODS GRAPHICS statement height= option before the PROC SGPLOT code.

ods region x=4in y=.5in ; 
ods graphics on / reset noborder height=3.5in;

Adding the table to the PDF

The bottom table is created by PROC REPORT along with some “power assist” from PROCs ODSTEST and FORMAT. This region is defined only with a Y= specification as I want REPORT’s table to take up the width of the entire region. The REPORT table will be centered by default, but ODSTEXT= will not, hence the j=c style override.

ods region y=4in; 

proc format;
value myfmt low-40="^{style [foreground=red] ^{unicode 2193} "
           40-high="^{style [foreground=green] ^{unicode 2191} ";
run;

proc odstext ;
   p " ";
   p "A subset of SASHELP.CARS where MPG_HIGHWAY is greater than 40 " / style={font=(", Albany",10pt,bold) just=c};
 run;

proc report data=sashelp.cars(where=(mpg_highway gt 40 and cylinders eq 4)) spanrows
style(report)={posttext="^{style [font_weight=bold] PROC FORMAT uses inline formatting and the Unicode style function to differentiate models based on the combined MPG}" };
col make model mpg_highway mpg_city avg type enginesize horsepower drivetrain;
define make / order;
define avg  / computed "Combined MPG" format=8. style(column)={posttext=myfmt.};
compute avg;
   avg=sum(mpg_highway.sum,mpg_city.sum)/2;
endcomp;
run;

Here are the results:

Using ODS LAYOUT feature to create and place a PROC REPORT table
We “put the brakes on” by closing the LAYOUT and the PDF destination:

ods layout end;
ods pdf close;

I hope you have enjoyed “kicking the tires” on my favorite destination. Are you excited about getting this new and updated model? If so, give your SAS dealership (ahem, representative) a call and upgrade today!

Please read the fine print:

If you have been an intrepid ODS LAYOUT coder prior to SAS 9.4, you are likely to see different results from your ODS LAYOUT/REGION statements when you move to SAS 9.4. If using the legacy style, styles.printer, does not correct the results, use Scott Huntley’s paper “An Insider’s Guide to ODS LAYOUT Using SAS® 9.4” . It is an excellent resource for coders moving ODS LAYOUT code from previous releases.

If you are moving from a SAS release prior to version 9.2, Scott and I wrote this paper “Getting the Right Report (Again): Your Compatibility Guide for ODS PDF 9.2” to discuss changes that took place for ODS PDF in that version.

Scott and Woody Middleton introduce you to the new features for ODS PDF in SAS 9.3 in "A Different Point of View with ODS PDF in SAS®9.3".

SAS has provided printable tip sheets for ODS PDF, ODS LAYOUT, PROC ODSTEXT, PROC ODSLIST, ODS GRAPHICS and more.

Share

About Author

Bari Lawhorn

Sr Principal Technical Support Analyst

Bari Lawhorn is a Senior Principal Technical Support Analyst in the Foundation SAS group in Technical Support, where she has provided general support for the DATA step and Base procedures for the past 22 years. Bari has specialized in support for the SAS Output Delivery System since its inception, is part of a Technical Support NLS (National Language Support) 'Virtual team', and supports SAS Studio.

2 Comments

  1. Bari,

    The Paper Title "An Insider’s Guide to ODS LAYOUT Using SAS® 9.4" presented at this year's SAS Gobal Forum was indeed a GEM of a Paper. Answered many of my questions on the Margin issues and Pagination Issues i was noticing with ODS LAYOUT after tranisitioning from 9.2M3 to 9.4M1. I just want to request that a Similar Papr or SAS Support Note be published for even the Report Writing Interface (RWI) , which too went into Production in SAS 9.4. Especially what changed in RWI , what new Options were added ,what options no longer are applicable/needed etc and what should be one aware of while using RWI in SAS 9.4 in terms of Pagination Issues etc. I see that the "overrides" option in RWI is no longer being used in some of the papers on RWI that i came across Online. May be it is no longer needed.

    Thanks,

  2. Daniel Kummer on

    The OVERRIDES Argument has been renamed in the production version and is now called STYLE_ATTR. It is still used in the same way but it's scope has changed. We kept 'overrides' around as an alias so programs written in pre-production versions still work in later ones.

Leave A Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to Top