Chapter 7: Embedding Images in a Report

Introduction

Example: Tables Displaying Iris Flower Measurements

Goals for Embedding Images in Reports

Source Data

ODS Style Templates Used

Programs Used

Implementation

Setup Options, File Paths, and Image File Names

Program Setup Code

Example 1: Obtain Images as Column of Data

Code for Obtaining Images as Column of Data

Example 2: Repeated Images Above and Below Table

Code for Repeating Images Above and Below Table

Produce the Report

Example 3: Display Images as Column Headers

Code for Displaying Images as Column Headers

Example 4: Display Image in Page Title

Code for Displaying Images in Page Titles

Example 5: Display Image Above Body of Table

Code for Displaying Image Above Body of Table

Example 6: Display Watermark on Report

Chapter 7 Summary

Introduction

The combined capabilities of ODS and PROC REPORT allow for the presentation of professional, informative reports. Reports are even further enhanced by the ability to insert images into tables. Images can increase the attractiveness of reports and improve illustrative abilities for presenting information. With the evolution of SAS and ODS, SAS programmers now have the ability to insert images in a variety of locations within a report, such as “data” within a column, before and/or after the body of a report, as column headers, and in titles and footnotes.

Example: Tables Displaying Iris Flower Measurements

Variations of a report summarizing Iris flower data are produced. The reports display measures of sepal length, sepal width, petal length, and petal width for three different types of Iris species, “Setosa”, “Versicolor,” and “Virginica.” While the reports contain some overlapping information, the purpose of this chapter is to show how reports can be presented in different formats. Reports are created using the RTF and TAGSETS.RTF ODS destinations.

The following figures are created in this chapter:

Figure 7.1 – Displays images as a column of data.

Figure 7.2 – Displays three PROC REPORT tables in one RTF file. The table containing Iris measurements is sandwiched between two one-row tables that contain an image in every column.

Figure 7.3 – Displays images as column headers.

Figure 7.4 – Displays an image as part of a title.

Figure 7.5 – Displays an image over the table body and uses TAGSETS.RTF.

Figure 7.6 – Is the same as Figure 7.5, but with a reduced image size and a watermark added.

Figure 7.1 Images as Column of Data

image

Figure 7.2 Images Above and Below Table

image

 

Figure 7.3 Images as Column Headers

image

Figure 7.4 Image in a Page Title (appears on every page of a report)

image

image

Figure 7.5 Image Above Body of Table

image

Figure 7.6 Apply Watermark

image

Goals for Embedding Images in Reports

There are a number of ways to insert images into a table when using the REPORT procedure. The coding technique differs depending on the location of the image. This chapter presents various options for embedding images within a report. The chapter also demonstrates the use of various SAS-supplied ODS Style templates.

Source Data

The source data set is the SAS supplied data set SASHELP.IRIS (Fisher’s Iris Data, 1936). The data set contains information collected on the three species of IRIS named earlier: Setosa, Versicolor, and Virginica. The data collected includes species, sepal length and width, and petal length and width (all in millimeters). Table 7.1 shows a partial print of the data, and Table 7.2 displays the variable attributes of the data set.

The iris images used in this chapter were reprinted with permission of Greg McCullough, owner of Iris City Gardens in the greater Nashville area (http://www.iriscitygardens.com).

The printed book is presented in grayscale and does not display the actual colors of the images. Visit the author’s web page at http://support.sas.com/publishing/authors/fine.html to see color images.

Table 7.1 Partial Print of SASHELP.IRIS Data

Species

SepalLength

SepalWidth

PetalLength

PetalWidth

Setosa

50

33

14

2

Setosa

46

34

14

3

Setosa

46

36

10

2

Setosa

51

33

17

5

Setosa

55

35

13

2

Setosa

48

31

16

2

Setosa

52

34

14

2

Setosa

49

36

14

1

Setosa

44

32

13

2

Setosa

50

35

16

6

Setosa

44

30

13

2

Setosa

47

32

16

2

Setosa

48

30

14

3

Setosa

51

38

16

2

Setosa

48

34

19

2

Setosa

50

30

16

2

Setosa

50

32

12

2

Setosa

43

30

11

1

Setosa

58

40

12

2

Setosa

51

38

19

4

 

Table 7.2 Contents of SASHELP.IRIS Data

#

Variable

Type

Len

Label

1

Species

Char

10

Iris Species

2

SepalLength

Num

8

Sepal Length (mm)

3

SepalWidth

Num

8

Sepal Width (mm)

4

PetalLength

Num

8

Petal Length (mm)

5

PetalWidth

Num

8

Petal Width (mm)

 

ODS Style Templates Used

A variety of ODS Style templates are used for the different reports.

Templates used include:

 

• Figure 7.1: SASWEB

• Figure 7.2: TORN

• Figure 7.3: SASWEB

• Figure 7.4: BANKER

• Figure 7.5: FANCYPRINTER

• Figure 7.6: FANCYPRINTER

Each template is specified in the ODS RTF / TAGSETS.RTF statement for a particular figure. Style overrides are applied in the TITLE and PROC REPORT statements to modify styles unique to a report.

Programs Used

All of the figures are created in one program named CH7Images.SAS.

Implementation

Setup Options, File Paths, and Image File Names

Common program features that apply to more than one figure are set up at the beginning of the program. These include:

 

• The ODS escape character

• The SAS system options NODATE and NONUMBER

• The output path for reports

• The image file path (input path), which is “C:TEMP”

• Creating macro variables (for the case when species are separate variables)

• Creating formats (for the case when images correspond to the variable SPECIES’ values)

Prior to programming, the needed images were saved to the author’s “C:TEMP” folder.

Program Setup Code

** Program Setup;

ods escapechar = “^”;

options nodate nonumber orientation=portrait;

 

** Output Path;

%let outpath = C:UsersUserMy DocumentsAPR;

 

** Paths to Images as Macro Variables;

%let setosa           = "c: empiSetosacp10.png";

%let versicolor     = "c: empiVersicolorcp10.png";

%let virginica       = "c: empiVirginicacp10.png";

%let versicolorw   = "c: empiVersicolorsm30.jpg";

%let versicolorw2 = "c: empiVersicolorsm20.jpg";

 

** Paths to Images as Formats;

proc format;

   value $flower

     "Setosa"       = "c: empiSetosacp10.png"

     "Versicolor" = "c: empiVersicolorcp10.png"

     "Virginica"   = "c: empiVirginicacp10.png";

run;

We need to declare the ODS escape character before we can use it for the ODS functions used throughout the chapter code. The ODS ESCAPECHAR is declared as the caret symbol (“^”).

NODATE suppresses the default date printed above SAS output. NONUMBER suppresses the SAS page numbers. The page orientation is set as portrait.

The output path to which all reports will be sent is specified in the macro variable OUTPATH.

Macro variables are created so we do not have to repeatedly type the file paths and names.

Likewise, the $FLOWER format is created so that we do not have to repeatedly type the file paths and names.

Example 1: Obtain Images as Column of Data

Figure 7.1 Images as Column of Data

Description: Figure 7.1 Images as Column of Data

The first example, Figure 7.1, portrays images in the Species column of the report. The key tasks include:

 

• Creating the $FLOWER format (which has already been done in the Program Setup Code).

• Applying the $FLOWER format to the PREIMAGE= attribute in the SPECIES DEFINE statement.

Code for Obtaining Images as Column of Data

** IMAGES AS COLUMN DATA;

ods _all_ close;

ods rtf style=sasweb file="&outpath.Ch7_column.rtf"

bodytitle;

 

title height=16 pt color=CX6D5299 bold font=Garamond "Flower: Iris";

 

footnote color=black bold justify=left font=Garamond height=11 pt

                 "^S={asis=on}                        Note: All measurements are reported in millimeters";

 

proc report data=sashelp.iris nowd missing split=“|” center

   style(header)=[background=CX6D5299 font_size=11 pt font_weight=bold

                            font_face=Garamond]

   style(column)=[cellwidth=1.1 in vjust=m just=d font_weight=bold

                             font_face=Garamond font_size=11 pt];

 

** Create Aliases so that Multiple Statistics can be Reported;

column ("SPECIES" species)

 

             petallength petallength=plength2

             petalwidth   petalwidth=pwidth2

             ("PETAL" ("Length" plmeanmed) ("Width" pwmeanmed))

 

             sepallength sepallength=slength2

             sepalwidth   sepalwidth=swidth2

             ("SEPAL" ("Length" slmeanmed) ("Width" swmeanmed));

 

   define species         / " " group style(column)=[preimage=$flower.

                                     protectspecialchars=off cellwidth=1.24 in vjust=m];

   ** Statistics;

   define petallength /   mean noprint;

   define plength2     /   median noprint;

   define petalwidth  /   mean noprint;

   define pwidth2      /   median noprint;

   define sepallength /   mean noprint;

   define slength2     /   median noprint;

   define sepalwidth /   mean noprint;

   define swidth2     /   median noprint;

 

   ** Print Computed Variables;

   define plmeanmed     / "" computed ;

   define pwmeanmed   / "" computed ;

   define slmeanmed     / "" computed ;

   define swmeanmed   / "" computed ;

 

   ** COMPUTED (And Printed) Columns;

   compute plmeanmed /char length=60;

       plmeanmed= "Mean: " || strip(put(petallength.mean,8.2)) ||"^n" ||

                             "Median: " || strip(put(plength2,10.2));

   endcomp;

 

   compute pwmeanmed /char length=60;

       pwmeanmed= "Mean: " || strip(put(petalwidth.mean,8.2)) ||"^n" ||

                               "Median: " || strip(put(pwidth2,10.2));

   endcomp;

 

   compute slmeanmed /char length=60;

       slmeanmed= "Mean: " || strip(put(sepallength.mean,8.2)) ||"^n" ||

                             "Median: " || strip(put(slength2,10.2));

   endcomp;

 

   compute swmeanmed /char length=60;

       swmeanmed= "Mean: " || strip(put(sepalwidth.mean,8.2)) ||"^n" ||

                              "Median: " || strip(put(swidth2,10.2));

   endcomp;

run;

ods _all_ close;

ods html;

title;

footnote;

 

SASWEB is chosen as the ODS Style Template to arrive at the overall table look. The BODYTITLE option is added to the ODS RTF statement so that titles and footnotes will appear directly above and below the table, rather than in the header and footer sections of the page.

The style of the title is modified by applying the height, color, and font options. The HEIGHT= option specifies the point size for the title, in this case, 16 pt. The font color is specified as the RGB color code CX6D5299, which represents “Light purplish blue.” An RGB color code list is provided in http://support.sas.com/techsup/technote/ts688/ts688.html. The font weight and type are specified as bold Garamond.

The spaces prior to the text in the footnote are intentional, so the text will line up with the table. The ASIS=ON style attribute requested with the style function is necessary to preserve the leading spaces.

Style overrides for headers and columns are defined in the PROC REPORT statement. The header background is set to the color of “Light purplish blue” (CX6D5299). The font face is changed to Garamond and bolded. The font size is set to 11 pt.

The column data has additional specifications. The vertical justification of data is specified as shown in the middle of the cell (with vjust=m). The width of the cells is specified as 1.1 inches. The horizontal justification is decimal aligned (just=d). The font face is Garamond and the font weight is set to bold.

Aliases are created for each of the four original measurement variables (petallength, petalwidth, sepallength, sepalwidth) so multiple statistics (i.e. mean and median) can be produced for each variable. Spanning headers are created around the variables to be printed.

The PREIMAGE= attribute is added to the Species DEFINE statement column(style) specification to add the iris images. The format $FLOWER is added to apply the appropriate image to each species value (Setosa, Versicolor, and Virginica).

We use a set of NOPRINTED variables to obtain statistics:

• Means and medians are obtained for the petal and sepal lengths and widths by specifying either MEAN or MEDIAN as the statistic for these ANALYSIS variables.

• Means use the original variable name (i.e. PETALLENGTH, PETALWIDTH, SEPALLENGTH, SEPALWIDTH) and medians use the alias name (i.e. PLENGTH2, PWIDTH2, SLENGTH2, SWIDTH2) declared in the COLUMN statement. The use of the alias names allows us to calculate more than one statistic (in this case, median) for the same variable.

• We suppress the printing of the individual mean and median columns because we will print COMPUTE block variables which create custom character strings containing the needed information. The COMPUTED variables stack the mean and median within each petal and sepal cell, as shown in the following example for the Setosa Species.

 

Description: image shown here

The custom character strings are created via COMPUTE blocks. This process is needed for Petal Length, Petal Width, Sepal Length, and Sepal Width (thus four COMPUTE blocks). Each character string concatenates the text “Mean”, a character version of the mean value, the newline function (specified by our escape character followed by “n”), the word “Median,” and the character version of the median value. These computed variables are printed in the final report.

Example 2: Repeated Images Above and Below Table

This section describes how to create Figure 7.2, which treats images as variables (IMG1, IMG2, and IMG3) and displays them as repeated columns in the REPORT procedure above and below the measurements table.

Figure 7.2 Images Above and Below Table

Description: Figure 7.2 Images Above and Below Table

Highlights of this section include:

 

• Creating a one observation data set that contains the three images as variables (named IMG1, IMG2, and IMG3).

• Transposing the IRIS data set to contain two variables (named PARAM and MEAS) and a record for each measurement (Petal Length, Petal Width, Sepal Length, and Sepal Width).

• Running three PROC REPORTS sandwiched in the same ODS RTF report

∘ PROC REPORT, repeating columns of IMG1, IMG2, IMG3

∘ PROC REPORT of the transposed IRIS data

∘ PROC REPORT, repeating columns of IMG1, IMG2, IMG3 (repeat of the first PROC REPORT).

Code for Repeating Images Above and Below Table

 

** Create Data Set with One Observation and Three Images;

** Single quotes used on outside since macro variable paths use double

     quotes;

data img;

length img1-img3 $100. ;

     img1=’^S={postimage=&setosa}’;

     img2=’^S={postimage=&versicolor}’;

     img3=’^S={postimage=&virginica}’;

     blank=“ “;

run;

 

 

** Create Transposed Iris Data Set with Parameter Identifier;

data tiris(drop=sepal: petal:);

   length descrip $16;

   format meas 8.2;

  

   set sashelp.iris;

  

   descrip = “Petal Length”;   meas = petallength; output;

   descrip = “Petal Width”;    meas = petalwidth;   output;

   descrip = “Sepal Length”;  meas = sepallength; output;

   descrip = “Sepal Width”;   meas = sepalwidth;   output;

run;

 

The one observation data set named IMG is created. Because the variables IMG1, IMG2, and IMG3 contain the escape character and inline style function (S={}), these variables will be rendered as images in the ODS destination. Note that single quotes are used to surround the style function because double quotes were used in the macro variables defined in the earlier %LET statements. As an example, what we’re really setting IMG1 to is

 

img1='^S={postimage="c: empiSetosacp10.png"}';

 

The IRIS data set is transposed so that we can get each measurement along with a description as its own record. Table 7.3 displays a partial print of the new data set named TIRIS.

Table 7.3 Partial PRINT of Transposed IRIS

descrip

Species

Meas

Sepal Length

Setosa

50

Sepal Width

Setosa

33

Petal Length

Setosa

14

Petal Width

Setosa

2

Sepal Length

Setosa

46

Sepal Width

Setosa

34

Petal Length

Setosa

14

Petal Width

Setosa

3

Sepal Length

Setosa

46

Sepal Width

Setosa

36

Petal Length

Setosa

10

Petal Width

Setosa

2

Sepal Length

Setosa

51

Sepal Width

Setosa

33

Petal Length

Setosa

17

Petal Width

Setosa

5

Sepal Length

Setosa

55

Sepal Width

Setosa

35

Petal Length

Setosa

13

Petal Width

Setosa

2

Sepal Length

Setosa

48

Produce the Report

 

** REPEATED IMAGES ABOVE AND BELOW TABLE;

ods _all_ close;

ods rtf style=torn file=“&outpath.Ch7sndwch.rtf” startpage=no;

 

title “Flower: IRIS”;

 

** FIRST PROC REPORT OF IMG DATA SET;

proc report data=img nowd missing split=“|” center

   style=[frame=void rules=none protectspecialchars=off]

   style(column)=[font_size=8 pt just=c cellwidth=1 in];

 

   column img1 img2 img3 img1 img2 img3;

   define img1 / ““;

   define img2 / ““;

   define img3 / ““;

run;

 

** PROC REPORT FOR DATA TABLE;

proc report data=tiris nowd missing split=“|” center

   style=[frame=void]

   style(header)=[font_size=14 pt font_weight=bold background=white]

   style(column)=[cellwidth=1.3 in font_size=10 pt just=c]

   out=PROUT;

 

column   ("Measure|(Mean mm)" descrip)
               ("Species" species), (meas meas=meas2);

 

   define species / across "";

   define descrip / group   ““ style(column header)=[just=l cellwidth=2.1 in];

   define meas    /  mean   ““;

   define meas2  /  median noprint;   /** used for Figure 7.3 **/

run;

 

** SECOND PROC REPORT OF IMG DATA SET;

proc report data=img nowd missing split=“|” center

   style=[frame=void rules=none protectspecialchars=off]

   style(column)=[font_size=8 pt just=c cellwidth=1 in];

 

   column img1 img2 img3 img1 img2 img3;

   define img1 / ““;

   define img2 / ““;

   define img3 / ““;

run;

ods _all_ close;

ods html;

title;

footnote;

 

For Figure 7.2, TORN is declared as the ODS Style Template to use. The STARTPAGE option is set to “no” because without this setting, the three separate REPORT procedures would each appear on their own page.

The first PROC REPORT repeatedly displays the one record data set IMG variables as columns with the statement

 

COLUMN img1 img2 img3 img1 img2 img3;  

The second PROC REPORT provides the data table. The DESCRIP column is DEFINEd as GROUP, and the SPECIES column as ACROSS, so that Species values (Setosa, Versicolor, Virginica) become columns that contain Petal Length, Petal Width, Sepal Length, and Sepal Width measurements.

The third PROC REPORT again repeatedly displays the one record data set IMG variables as columns with the statement

 

COLUMN img1 img2 img3 img1 img2 img3;

Note that an output data set (PROUT) is created and medians are derived (though not printed in Figure 7.2). The PROUT data set is the source data set for the next figure, Figure 7.3.

Example 3: Display Images as Column Headers

This section demonstrates how to create Figure 7.3, which shows images as column headers.

Figure 7.3 Images as Column Headers

Description: Figure 7.3 Images as Column Headers

Note that the input for the REPORT procedure is the PROC REPORT output dataset created in the boxed code from Example 2. Table 7.4 shows a print of the data set PROUT.

Table 7.4 PROC REPORT OUTPUT DATA SET PROUT

Descrip

_C2_

_C3_

_C4_

_C5_

_C6_

_C7_

_BREAK_

Petal Length

14.62

15.00

42.60

43.50

55.52

55.50

 

Petal Width

2.46

2.00

13.26

13.00

20.26

20.00

 

Sepal Length

50.06

50.00

59.36

59.00

65.88

65.00

 

Sepal Width

34.28

34.00

27.70

28.00

29.74

30.00

 

As shown in Table 7.4, the ACROSS columns in the output data set are in the form _Cn_, where n indicates the column number. In this case, columns _C2_ and _C3_ (Column 2 and Column 3) represent Setosa Mean and Setosa Median, respectively. _C4_ and _C5_ (Column 4 and Column 5) represent Versicolor Mean and Median, respectively. _C6_ and _C7_ (Column 6 and Column 7) represent Virginica Mean and Median, respectively.

Code for Displaying Images as Column Headers

** IMAGES AS COLUMN HEADERS;

ods _all_ close;

ods rtf style=sasweb file=“&outpath.Ch7_header.rtf”;

title height=20 pt bold italic bcolor=CX6D5299 color=white font=Georgia “Flower: Iris”;

proc report data=PROUT nowd missing split=“|”

   style=[protectspecialchars=off cellspacing=5]

   style(header)=[font_weight=bold font_size=12 pt background=white

                           foreground=CX483D8B]

   style(column) = [cellwidth=.8 in just=c font_size=10 pt];

   ** Insert Images as Spanning Headers;

   column (“Measure (mm)” descrip)

       ('^S={pretext="Setosa" postimage=&setosa}'

         ("Mean" _c2_) ("Median" _c3_)

       )

 

       ('^S={pretext="Versicolor" postimage=&versicolor}'

         ("Mean" _c4_) ("Median" _c5_)

       )

 

       ('^S={pretext="Virginica" postimage=&virginica}'

         ("Mean" _c6_)("Median" _c7_ )

       );

   ** DEFINE Specifications;

   define descrip / order ““

                             style(column)=[just=l cellwidth=1.6 in indent=.2 in];

   define _c2_ / ““;

   define _c3_ / ““;

   define _c4_ / ““;

   define _c5_ / ““;

   define _c6_ / ““;

   define _c7_ / ““;

run;

ods _all_ close;

ods html;

title;

footnote;

Figure 7.3 uses the SASWEB ODS Style Template.

The title style is modified by applying the height (font size), bold, italic, bcolor (background color) color (foreground color) and font (font type) options. The background color uses RGB code CX6D5299, which is “Light purplish blue.”

Style overrides for the overall output, headers and columns are specified in the PROC REPORT statement. For the overall report, PROTECTSPECIALCHARS=OFF is specified so that SAS and ODS do not try to "protect" the backslash characters found in the images paths. The cell spacing is increased to provide thicker borders between the cells.

Header font is set to bold 12 pt. font. The background color is changed from the default SASWEB blue to white. The font color is changed from the default SASWEB white to “DarkSlateBlue” (foreground=CX483D8B).

Column cellwidth is set to .8 inches, column data is centered, and its font is changed to 10 pt. (from the default SASWEB 9.5 pt.).

The images are inserted as Spanning Headers in the COLUMN statement. The PRETEXT= and POSTIMAGE= options are used within ODS style functions. The PRETEXT= option is used to add the species name prior to the species image (POSTIMAGE). The species macro variables are called for the POSTIMAGEs, for example, postimage= &setosa resolves to postimage= "c: empiSetosacp10.png")

The DESCRIP column style is formatted slightly different than the other columns. The data is left justified, given a larger cell width, and indented .2 inches from the left. All column labels are set to null in the DEFINE statements so the variable names are not printed.

Example 4: Display Image in Page Title

This section demonstrates how to create Figure 7.4, which displays an image in the page title. Because the image is part of the page title, the image appears on every page of the report. The PREIMAGE= attribute is used to obtain an image before the title text. Although not shown, the same technique can be used for page footnotes.

Figure 7.4 Image in a Page Title (partial print of Pages 1 and 2)

Description: Figure 7.4 Image in a Page Title (partial print of Pages 1 and 2)

Description: image shown here

Code for Displaying Images in Page Titles

** IMAGE IN TITLE;

ods _all_ close;

ods rtf file="&outpath.Ch7_titleimg.rtf" style=banker;

 

title h=14 pt '^S={preimage=&versicolor}

    Flower: Iris ^{style [font_face=wingdings]u}

    Species: Versicolor ^{style [font_face=wingdings]u}

    Page ^{thispage} of ^{lastpage}';

 

proc report data=sashelp.iris(where=(species="Versicolor")) nowd missing

   split=“|” center

   style(header)=[just=center]

   style(column)=[just=center cellwidth=1.2 in];

 

   column species ("SEPAL" sepallength sepalwidth)

                             ("PETAL" petallength petalwidth);

 

   define species        / "Species" NOPRINT ;

   define sepallength / "Length (mm)"     format=8.;

   define sepalwidth  / "Width (mm)"      format=8.;

   define petallength / "Length (mm)"     format=8.;

   define petalwidth  / "Width (mm)"      format=8.;

run;

ods _all_ close;

ods html;

title;

footnote;

 

BANKER is the ODS Style Template for this example.

A style function places the PREIMAGE= option directly in the TITLE statement. This style is started and ended with brackets (“{}”).

Additional style functions are nested within the same TITLE statement. The ^{style [font_face=wingdings]u} creates the diamond symbol, and this is placed between the “Flower: Iris”, “Species: Versicolor” and   “Page” text.

The “Page” text is followed by two other ODS functions: {thispage}, the text “of”, and the function {lastpage}.

Example 5: Display Image Above Body of Table

This example demonstrates how to create Figure 7.5, which shows how to insert an image above the body of the PROC REPORT table. Unlike Example 4, for which the image prints on every page, this example prints the image only once, before the table. The image is inserted with the STYLE= attribute (rather than a STYLE function) within the PROC REPORT statement. The PREIMAGE= attribute is nested within the STYLE= attribute. Although not shown, the POSTIMAGE= attribute can be used to insert the image below the table body. The “(Continued)” text at the bottom of Figure 7.5 is part of the report and is obtained with ODS TAGSETS.RTF.

Figure 7.5 Image Above Body of Table

Description: Figure 7.5 Image Above Body of Table

Code for Displaying Image Above Body of Table

** IMAGE ABOVE BODY OF REPORT;

ods _all_ close;

ods tagsets.rtf file="&outpath.Ch7_bodyimg.rtf" style=fancyprinter;

 

title h=18 pt “ FLOWER: Iris   ^{style [font_face=wingdings
color=darkpurpleblue]|}     SPECIES: Versicolor”;

 

proc report data=sashelp.iris(where=(species="Versicolor")) nowd missing

     split=“|” center

     style(report)=[preimage=&versicolorw cellpadding=0 cellspacing=0]

     style(column)=[just=center cellwidth=1.15 in font_size=11 pt]

     style(header)=[font_size=11 pt font_weight=bold];

 

   column

       species

       ("^{newline}^{style [font_weight=bold]

          Versicolor Sepal and Petal Measurements}^{newline}"

          sepallength sepalwidth petallength petalwidth

       );

 

   define species /   noprint;

run;

ods _all_ close;

ods html;

title;

footnote;

Note that TAGSETS.RTF is the ODS destination specified. This is because we want the default TAGSETS.RTF “Continued” note to appear at the bottom of each page until the last page of the report.

The ODS Style Template “FancyPrinter” provides the template for this report.

A flower symbol is inserted between the Flower and Species descriptions by applying wingdings font face to the pipe (“|”) character with a style function.

The PREIMAGE= attribute is placed in a style(report)= attribute as part of the PROC REPORT statement.

Though SPECIES is not printed (because this report was subset on only one species, “Versicolor”) this character variable is included so the four ANALYSIS variables (sepallength, sepalwidth, petallength, and petalwidth) are not summed. (The addition of the DISPLAY variable prevents the ANALYSIS variables from being summed. By default, the character variable SPECIES is DISPLAY, and the numeric variables SEPALLENGTH, SEPALWIDTH, PETALLENGTH, and PETALWIDTH are ANALYSIS).

Suppress the printing of the SPECIES column with NOPRINT.

Example 6: Display Watermark on Report

Another feature available with ODS TAGSETS.RTF is a watermark option, as shown in Figure 7.6.

Figure 7.6 Apply Watermark

Description: Figure 7.6 Apply Watermark

The Example 6 program requires three changes to the Example 5 program:

 

• Change the output file name so that it does not overwrite Example 5.

• Include the WATERMARK= option in the ODS TAGSETS.RTF statement:

 

ods tagsets.rtf file="c: empCh7_wmbodyimg.rtf" style=fancyprinter

   options (watermark="DRAFT");

While the word “DRAFT” is chosen here, the programmer can choose the text to serve as the watermark.

 

• Use a reduced size image so that the watermark covers the entire table. We use the image stored in the macro variable VERSICOLORW2 in the PROC REPORT statement.

 

style(report)=[preimage=&versicolorw2 cellpadding=0 cellspacing=0]

Chapter 7 Summary

Table 7.5 summarizes some of the tasks that were performed to embed images in this chapter’s report examples.

Table 7.5 Summary of Tasks

Task

Summary

Setup Image Paths and File Names

 

The needed images were already saved to the author’s folder (“C:TEMP”).

The ODS Escapechar was declared.

Options to be used for all reports were specified.

Needed macro variables and formats were created.

Display Images in Column Data

 

A format was created to attach each image to a flower species name. The format was applied to the Species column in the SPECIES DEFINE statement.

Repeated Images Above and Below Table

 

A one observation data set containing three variables was created. Assignment statements set each variable to its corresponding image along with the needed style function specifications, for example   img1='^S={postimage="c: empiSetosacp10.png"}’;

PROC REPORT was invoked three times, with the IRIS measurements data sandwiched between the images (“IMG”) data set.

Display Images as Column Headers

 

PROC REPORT was used to transpose the IRIS data and produce a data set in which the species are columns in the form _C2_, _C3_, and _C4_..._C7. Using style functions with the PREIMAGE= attribute, the images were specified as spanning headers in the COLUMN statement, for example ('^S={pretext="Setosa" postimage=&setosa}' ("Mean" _C2_) ("Median" _C3_))

Display Image in Page Title

 

Using a style function again, the images were placed directly in the title statement. A simplified example is the title   '^S={preimage="c: empiVersicolorcp10.png"}   Flower: Iris';

 

Display Image Above the Table Body

 

The image is specified in the PROC REPORT statement, for example, proc report data=sashelp.iris nowd missing split='|' center
       style=[preimage="c: empiVersicolorsm30.jpg"];

 

A Watermark is Possible With ODS TAGSETS.RTF

For example, ods tagsets.rtf file="c: empodywmark.rtf" style=fancyprinter options (watermark="DRAFT");

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset