Example 6.12. Customizing the Appearance of a Report Produced by a DATA Step

Goal

Customize the appearance of the report produced in Example 4.2 by modifying style attributes with ODS. Send the output to a nonlisting destination.

Report

    Client Protocol Population
 Table 2.14
 Baseline Demographics
  ActivePlacebo 
 Number of Patients94106 
 Gender   
 Male41 (21%)46 (23%) 
 Female53 (27%)60 (30%) 
 Age (years)   
 Mean (SEM)52.1 (1.96)53.9 (1.74) 
 25th-75th33.7 - 67.337.7 - 69.1 
 Mm - Max21.0-84.720.5-84.8 
 No. Missing00 
 Race   
 Non-White37 (19%)33 (17%) 
 White57 (29%)73 (37%) 
 Height (inches)   
 Mean (SEM)65.4 (0.54)65.4 (0.54) 
 25th - 75th61.5 - 69.960.5 - 70.0 
 Mm - Max55.3 - 74.855.2 - 74.7 
 No Missing00 
 Weight (lbs)   
 Mean (SEM)188.2 (5.07)191.1 (4.43) 
 25th - 75th140.9-225.8159.2-223.7 
 Min - Max110.5-275.6110.4-277.0 
 No Missing00 

Example Features

Data SetDEMOG
Report ExampleExample 4.2
Preparatory StepsPROC FREQ

PROC MEANS

PROC SORT

PROC TRANSPOSE

DATA steps
Featured Steps and StatementPROC TEMPLATE

DATA step

ODS statement
Featured Step Statements and OptionsPROC TEMPLATE statements:

DEFINE COLUMN

DEFINE HEADER

DEFINE TABLE

STYLE=

COLUMN

HEADER=

TEXT

DATA step: FILE PRINT ODS statement

ODS ESCAPECHAR=

Inline formatting
Additional FeaturesDATA step programming
Output Destination of ExampleRTF
A Closer LookComparing DATA Steps That Send and Do Not Send Output to ODS Learning More about ODS Inline Formatting
Other Examples That Use This Data SetExample 4.2

Example Overview

The report in Example 4.2 presents statistics in a customized format that cannot be produced easily by a SAS procedure. The program in Example 4.2 uses a DATA step to write the summary statistics produced by PROC FREQ and PROC MEANS, which were saved in several output data sets.

Example 4.2 is a tabular summary report. It has titles and three columns. The first column lists the demographic categories. The second and third columns contain the statistics for the two groups, “Active” and “Placebo,” for each of the categories.

The report in this example takes advantage of the tabular structure of the Example 4.2 report and adds ODS features to the program to send the report to a nonlisting destination.

This program uses the same summary statistics data sets that PROC FREQ and PROC MEANS created in Example 4.2. Rather than processing the data sets in the DATA step as in Example 4.2, this program combines the summary statistic data sets into one data set. It sorts and restructures the observations in this new data set to fit the three-column format of the report. The primary purpose of the DATA _NULL_ step in this example is to send the three-column report to the output destination. The DATA step does minimal processing of the observations.

The FILE statement in the DATA step directs SAS to use a table definition to construct the report. A PROC TEMPLATE step before the DATA step creates the table definition. This table definition is saved in a template store and can be reused. The table definition defines three columns and some of the style attributes of these columns. The PROC TEMPLATE step also defines some of the style attributes of the headers in the table.

The FILE statement and the PUT statements in the DATA step communicate instructions to ODS. The FILE statement includes options that are specific to sending data to an ODS destination. The PUT statements write to the columns of the report and have a different syntax than in Example 4.2.

Specific formatting instructions for the titles and demographic categories are embedded in text strings. Instructions are preceded by a symbol defined with the ODS ESCAPECHAR= statement. This symbol followed by an “S” triggers ODS to intrepret the information that follows as instructions to set style attributes for the text that follows.

Program

 
/* Execute the PROC FORMAT, PROC FREQ, and PROC
 MEANS */
/* steps in Example 4.2 before executing the
 following*/

Concatenate the summary statistics data sets in the order they will be presented in the report.
data all;

Create variables that indicate the origin of the current observation.
  set t1(in=in1) t2(in=in2) t3(in=in3) t4(in=in4)
      t5(in=in5) t6(in=in6);

Define two character variables to hold the results and categories.
  length text $ 25 factor $ 50;

Define SECTION to track the demographic category. Define ROW to track placement within the section. Place the category text in the variable FACTOR. Save the formatted statistics results in the variable TEXT. Define the contents of section 1, the counts by treatment group.
  if in1 then do;
    section=1;
    row=1;
    factor='Number of Patients';
    text=put(count,4.);
    output;
  end;

Define the contents of section 2, the counts by gender and treatment group.
  else if in2 then do;
    section=2;
    if gender=0 then do;
      row=1;
      factor='Male';
    end;
    else if gender=1 then do;
      row=2;
      factor='Female';
    end;
    text=catx(' ', put(count,4.),
         cats('(',put(percent,3.),'%',')'));
    output;
  end;

Define the contents of section 4, the counts by race and gender.
  else if in4 then do;
    section=4;
    if race=0 then do;
      row=1;      
      factor='Non-White';
    end;
    else if race=1 then do;
      row=2;
      factor='White';
    end;
    text=catx(' ', put(count,4.),
         cats('(',put(percent,3.),'%',')'));
    output;
  end;

Define the contents of sections 3, 5, and 6, the statistics for age, height, and weight by treatment group.
  else if in3 or in5 or in6 then do;
    if in3 then section=3;
    else if in5 then section=5;
    else if in6 then section=6;

Specify the label and contents for the row with the means and standard errors.
    factor='Mean (SEM)';
    text=catx(' ', put(mean,5.1),
         cats('(',put(stderr,5.2),')'));
    row=1;
    output;

Specify the label and contents for the row with the interquartile range.
    factor='25th - 75th';
    text=catx(' ',put(q1,5.1),'-',put(q3,5.1));
    row=2;
    output;

Specify the label and contents for the row with the range.
    factor='Min - Max';
    text=catx(' ',put(min,5.1),'-',put(max,5.1));
    row=3;
    output;

Specify the label and contents for the row with the number of missing values.
    factor='No. Missing';
    text=put(nmiss,2.);
    row=4;
    output;
  end;
run;

Arrange the observations in the order they should appear in the report.
proc sort data=all;
  by section row factor;
run;

Reshape the ALL data set so that each observation in ALL2 now corresponds to a row in the report. Keep FACTOR with the transposed observation by including it on the BY statement.
proc transpose data=all out=all2;
  by section row factor;

Create a variable for each treatment group and assign the name of each variable the corresponding value of TMTDG, which is ACTIVE or PLACEBO.
  id tmtdg;

Assign the values of TEXT to the corresponding variable ACTIVE or PLACEBO.
  var text;
run;

Specify the character that indicates to ODS that what follows the character are style attributes and formatting instructions. Select a character that you know will not be part of a character value in your data.
ods escapechar='^';

Define titles and format them. Change the default style of italic to roman by setting the style with the escape character and S= specification.
title  justify=right '^S={font_style=roman}Client';
title2 justify=right '^S={font_style=roman}Protocol';
title3 justify=right '^S={font_style=roman
}Population';
title5 '^S={font_style=roman}Table 2.14';
title7 '^S={font_style=roman}Baseline Demographics';

Define style attributes of components of the report and define the layout of the report. Save this in the SASUSER library. This step has to be executed only once because the information is permanently saved in the SASUSER library.
proc template;

Define and save a heading that will be used in rendering the ACTIVE and PLACEBO columns of the report.
  define header sasuser.statscol;

Do not specify a background color of the header.
    style={background=_undef_};
  end;

Define a table definition that will be used in rendering the report.
  define table sasuser.demog;

Remove rules and the frame from the table layout.
    style={rules=none frame=void};

Specify three columns in the table that will later be associated with the variables in the analysis data set.
    column a b c;

Specify characteristics of column a.
    define column a;

Specify the characteristics of the heading for column a. Do not specify a background color and suppress the column heading.
      define header notext;
        style={background=_undef_};
        text ' ';
      end;

Specify the heading definition for column a, which is the heading defined previous to this statement.
      header=notext;
   end;

Specify characteristics of column b.
   define column b;

Center the contents of column b.
     just=center;

Specify the header definition for column b, which is defined above.
     header=sasuser.statscol;
   end;

Specify the characteristics of column c.
   define column c;

Center the contents of column c.
      just=center;

Specify the header definition for column c, which is defined above.
      header=sasuser.statscol;
    end;
  end;
run;

Do not send results to the LISTING destination.
ods listing close;

Send subsequent results to the RTF destination and save the results in a file.
ods rtf file='c:
eportsexample42.rtf';




data _null_;
  set all2;

Send the report to the ODS destination. Lay out the report according to the template SASUSER.DEMOG.
  file print ods=(template='sasuser.demog'

Specify the correspondence between the columns in the SASUSER.DEMOG table definition and the variables in the analysis data set.
             columns=(a=factor b=active
                      c=placebo));

Add formatting features at the beginning of each demographic section.
  if row=1 then do;

Write the value of FACTOR (“Number of Patients”) in the first section in bold.
   if section=1 then
      factor=cats("^S={font_weight=bold}" ,factor);
   else if section=2 then

Skip a line between sections.
           put /

Write specific text in bold in the cell corresponding to the first column and first row in each of the sections two through six.
             @1 "^S={font_weight=bold}Gender";
     else if section=3 then
         put / @1 '^S={font_weight=bold}Age (years)';
     else if section=4 then
         put / @1 '^S={font_weight=bold}Race';
     else if section=5 then
         put / @1 '^S={font_weight=bold}Height 
(inches)';
     else if section=6 then
         put / @1 '^S={font_weight=bold}Weight (lbs)';
  end;

Write the observation’s data to the report using the template specified on the FILE PRINT statement. Place the values of FACTOR in column 1, the values of ACTIVE in column 2, and the values of PLACEBO in column 3. These associations were made above in the FILE PRINT statement.
  put _ods_;
run;

Terminate sending output to the RTF destination.
ods rtf close;

Send subsequent output to the LISTING destination.
ods listing;


A Closer Look

Comparing DATA Steps That Send and Do Not Send Output to ODS

The DATA step in this program uses FILE and PUT statements to create the report. Example 4.2 also uses FILE and PUT statements to create its report. However, the syntax of these two statements in Example 4.2 is different from that in this example.

The program in Example 4.2 directs the placement of information on the page by computing and designating column and row positions. The PUT statement uses line control pointers and column control pointers to move a pointer to a specific byte location on a page.

The column pointers in this example’s program, however, do not explicitly direct output to a column character location. The direction is instead to an entire column. “Column” means something different when using ODS in the DATA step:

When you specify FILE PRINT, an “@3” moves the line pointer to byte location 3.
When you specify FILE PRINT ODS, an “@3” moves the line pointer to what ODS considers the third column of data in the tabular layout of the report.

The FILE statement with the ODS option and ODS suboptions controls different features than the FILE PRINT statement does. It tells SAS to bind the data component of your report to a table definition (template). In this example, this results in an RTF report whose basic structure is controlled by the SASUSER.DEMOG table definition.

The suboptions on the FILE PRINT ODS statement specify the table definition, and they associate variable names in the data set to columns in the table definition.

Since the likely reason you’re using ODS in a DATA step is because you need to prepare a highly formatted report, it would not be sensible to point to specific column and row locations as in Example 4.2. The software that manages your output destination would do a better job at positioning your data. For example, when you use a proportional font such as Times Roman, characters have different widths. Directing output to a specific byte location would cause strange looking results, with some characters surrounded by excess space and others running into other characters. The output in the “A Closer Look” section of Example 6.2 illustrates what happens when you try to explicitly position data when using a proportional font.

Learning More about ODS Inline Formatting

This example shows how you can insert formatting instructions within text strings. These instructions temporarily override existing instructions that are provided by the template.

To use ODS inline formatting, first submit the ODS ESCAPECHAR= statement to define an escape character that SAS will interpret as a trigger for inline formatting. Be sure that the character you pick will not be in your text. This example specified the caret (^).

Once the escape character has been defined, you can insert formatting instructions in your report. Following the escape character is the type of instruction, an equal sign, and the instructions enclosed in brackets. This example specified style-type instructions, and style is represented as “S.” The instructions remain in effect until the end of the text string, unless another instruction is encountered in the same text string.

If you want to revert to the original style of the text string after applying an inline formatting instruction, you can terminate the instruction as shown in the following TITLE statement. The text “Baseline Demographics” is printed with font size of 22 pt, whereas the remaining text in the title is printed in the font size that was in effect before the 22 pt attribute specification.

title '^S={font_size=22pt}Baseline Demographics^S={}
          (collected at initial visit)';

The syntax of the style attribute specifications is similar to that for style attributes in table definitions, PROC PRINT, PROC REPORT, and PROC TABULATE. For further examples of specifying style attributes, look at the other examples in this chapter, all of which use one of these four processes. For more detailed information, see SAS 9.1 Output Delivery System: User’s Guide and Base SAS 9.1 Procedures Guide (support.sas.com/v9doc).

There are additional instruction types that can be specified to do actions such as starting new lines, wrapping lines, and so on. Please refer to the SAS online documentation for this information (support.sas.com/v9doc).

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

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