Previous Page | Next Page

TEMPLATE Procedure: Creating Tabular Output

Example 4: Setting the Style Element for Cells Based on Their Values


PROC TEMPLATE features:

DEFINE TABLE statement:

NMVAR statement

NOTES statement

TRANSLATE INTO statement

DEFINE COLUMN statement:

BLANK_DUPS= attribute

CELLSTYLE AS statement

GENERIC= attribute

Other ODS features:

ODS HTML statement

FILE statement with ODS= option

PUT statement with _ODS_ argument

Data set: Grain_Production.
Format: $CNTRY..


Program Description

This example creates a template that uses different colors and font attributes for the text inside cells, depending on their values.

Note:   This example uses filenames that might not be valid in all operating environments. To successfully run the example in your operating environment, you might need to change the file specifications. See ODS HTML Statements for Running Examples in Different Operating Environments.  [cautionend]


Program

 Note about code
options nodate pageno=1 pagesize=60 linesize=72;
title "Leading Grain Producers";
 Note about code
proc template;
   define table shared.cellstyle;
 Note about code
   translate _val_=. into "No data";
 Note about code
   notes "NMVAR defines symbols that will be used to determine the colors
 of the cells.";
 Note about code
  nmvar low "Use default style."
        medium "Use yellow foreground color and bold font weight"
        high "Use red foreground color and a bold, italic font.";
 Note about code
   classlevels=on;
 Note about code
   define column char_var;
      generic=on;
      blank_dups=on;
   end;
 Note about code
   define column num_var;
      generic=on;
 Note about code
      justify=on;
 Note about code
      cellstyle _val_ <= low as data,
                _val_ <= medium as data
                         {color=green fontstyle=italic},
                _val_ <= high as data
                         {color=yellow fontweight=bold},
                    1 as data
                         {color=red fontstyle=italic 
                          fontweight=bold};
   end;
      
 Note about code
   end;
run;
 Note about code
ods html body="CellStyle-Body.htm";
 Note about code
%let low=10000;
%let medium=50000;
%let high=100000;
 Note about code
data _null_;
   set grain_production;
 Note about code
   file print ods=(
        template="shared.cellstyle"
 Note about code
        columns=(
           char_var=year(generic=on)
           char_var=country(generic=on format=$cntry.)
           char_var=type(generic=on)
           num_var=kilotons(generic=on format=comma12.)
           )
        );
 Note about code
   put _ods_;
run;
 Note about code
ods html close;

Listing Output of a Customized Table

Listing Output

 Note about figure
                        Leading Grain Producers                        1
                 Year    Country          Type         Kilotons

                 1995    Brazil           Corn           36,276
                                          Rice           11,236
                                          Wheat           1,516
                         China            Corn          112,331
                                          Rice          185,226
                                          Wheat         102,207
                         India            Corn            9,800
                                          Rice          122,372
                                          Wheat          63,007
                         Indonesia        Corn            8,223
                                          Rice           49,860
                                          Wheat         No data
                         United States    Corn          187,300
                                          Rice            7,888
                                          Wheat          59,494
                 1996    Brazil           Corn           31,975
                                          Rice           10,035
                                          Wheat           3,302
                         China            Corn          119,350
                                          Rice          190,100
                                          Wheat         109,000
                         India            Corn            8,660
                                          Rice          120,012
                                          Wheat          62,620
                         Indonesia        Corn            8,925
                                          Rice           51,165
                                          Wheat         No data
                         United States    Corn          236,064
                                          Rice            7,771
                                          Wheat          62,099

HTML Output of a Customized Table

HTML Output (Viewed with Microsoft Internet Explorer)

 Note about figure

[HTML Output (Viewed with Microsoft Internet Explorer)]

Previous Page | Next Page | Top of Page