Chapter Contents

Previous

Next
The TEMPLATE Procedure

Example 3: 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.

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

Note:   This example uses file names that may not be valid in all operating environments. To successfully run the example in your operating environment, you may need to change the file specifications. See Alternative 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";
   notes "to determine the colors of the cells.";
 Note about code
  nmvar low 'Use default style.'
        medium 'Use yellow foreground and bold font weight'
        high 'Use red foreground 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
                         {foreground=green font_style=italic},
                _val_ <= high as data
                         {foreground=yellow font_weight=bold},
                    1 as data
                         {foreground=red font_style=italic 
                          font_weight=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
Listing Output of a Customized Table
 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
Both the table customizations and the style customizations appear in the HTML output. Table customizations include the suppression of values that do not change from one row to the next and the translation of missing values to No data. The style customizations include the colors and font styles that are specified in the CELLSTYLE-AS statement. [HTML Output]


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.