Previous Page | Next Page

TEMPLATE Procedure: Creating Tabular Output

Example 2: Comparing the EDIT Statement with the DEFINE TABLE Statement


PROC TEMPLATE features:

EDIT statement

COLUMN statement

DEFINE statement:

STYLE= attribute

NOTES statement

DYNAMIC statement

Other ODS features:

ODS PATH statement

ODS HTML statement

ODS HTML CLOSE statement

Data set: Exprev.


Program Description

This example compares the use of an EDIT statement with a DEFINE TABLE statement for the same table template. The first program uses the EDIT statement to change the Base.Summary table template. The foreground color of the NOBS column is changed to green. The other templates and attributes of the Base.Summary table template remain the same. The second program uses the DEFINE TABLE statement to define a new table using the same name, Base.Summary. The NOBS column is the only column defined in the new table template. When the PROC SUMMARY step executes, only the NOBS column is printed. The only style attribute that formats the column is the color=green attribute.


Program 1

 Note about code
ods path work.templat (update) sashelp.tmplmst (read);
proc template;
    edit Base.Summary;
    edit nobs;
    style={color=magenta background=white}; 
end;                                                                    
                                                                 
end;                                                                       
run;   

ods html file="temp.html";

proc summary data=exprev print;
    class Sale_Type;
run;

ods html close; 

HTML Output Using an Edited Table Template for Base.Summary

 Note about figure

[HTML Output Using an Edited Table Template for Base.Summary]

Base.Summary Table Template Modified by the EDIT Statement

 Note about figure
proc template;                                                                
   define table Base.Summary / store = SASUSER.TEMPLAT;                       
      notes "Summary table for MEANS and SUMMARY";                            
      dynamic one_var one_var_label one_var_name clmpct;                      
      column class nobs id type ways (varname) (label) (min) (max) (range) (n)
         (nmiss) (sumwgt) (sum) (mean) (uss) (css) (var) (stddev) (cv) (stderr
         ) (t) (probt) (lclm) (uclm) (skew) (kurt) (median) (mode) (q1) (q3) (
         qrange) (p1) (p5) (p10) (p25) (p50) (p75) (p90) (p95) (p99);         
      header h;                                                               
      define p99;                                                             
         header = "99th Pctl";                                                
         generic;                                                             
      end;                                                                    
      define p95;                                                             
         header = "95th Pctl";                                                
         generic;                                                             
      end;                                                                    
      define p90;                                                             
         header = "90th Pctl";                                                
         generic;                                                             
      end;                                                                    
      define p75;                                                             
         header = "75th Pctl";                                                
         generic;                                                             
      end;                                                                    
      define p50;                                                             
         header = "50th Pctl";                                                
         generic;                                                             
      end;                                                                    
      define p25;                                                             
         header = "25th Pctl";                                                
         generic;                                                             
      end;                                                                    
      define p10;                                                             
         header = "10th Pctl";                                                
         generic;                                                             
      end;                                                                    
      define p5;                                                              
         header = "5th Ptcl";                                                 
         generic;                                                             
      end;                                                                    
      define p1;                                                              
         header = "1st Pctl";                                                 
         generic;                                                             
      end;                                                                    
      define qrange;                                                          
         header = "Quartile Range";                                           
         generic;                                                             
      end;                                                                    
      define q3;                                                              
         header = "Upper Quartile";                                           
         generic;                                                             
      end;                                                                    
      define q1;                                                              
         header = "Lower Quartile";                                           
         generic;                                                             
      end;                                                                    
        
 define mode;                                                            
         header = "Mode";                                                     
         generic;                                                             
      end;
       define median;                                                          
         header = "Median";                                                   
         generic;                                                             
      end; 
       define kurt;                                                            
         header = "Kurtosis";                                                 
         generic;                                                             
      end;                                                                    
      define skew;                                                            
         header = "Skewness";                                                 
         generic;                                                             
      end;                                                                    
      define uclm;                                                            
         define header huclm;                                                 
            text "Upper " clmpct BEST8. %nrstr("%%/CL for Mean");             
            split = "/";                                                      
         end;                                                                 
         header = huclm;                                                      
         generic;                                                             
      end;                                                                    
      define lclm;                                                            
         define header hlclm;                                                 
            text "Lower " clmpct BEST8. %nrstr("%%/CL for Mean");             
            split = "/";                                                      
         end;                                                                 
         header = hlclm;                                                      
         generic;                                                             
      end;                                                                    
      define probt;                                                           
         parent = Common.ParameterEstimates.Probt;                            
         generic;                                                             
      end;                                                                    
      define t;                                                               
         parent = Common.ParameterEstimates.tValue;                           
         generic;                                                             
      end;                                                                    
      define stderr;                                                          
         header = "Std Error";                                                
         parent = Common.ParameterEstimates.StdErr;                           
         generic;                                                             
      end;                                                                    
      define cv;                                                              
         header = "Coeff of Variation";                                       
         generic;                                                             
      end;                                                                    
      define stddev;                                                          
         header = "Std Dev";                                                  
         generic;                                                             
      end;                                                                    
      define var;                                                             
         header = "Variance";                                                 
         generic;                                                             
      end;                                                                    
      define css;                                                             
         define header hcss;                                                  
            text2 "CSS";                                                      
            text "Corrected SS";                                              
         end;                                                                 
         header = hcss;                                                       
         generic;                                                             
      end;                                                                    
      define uss;                                                             
         define header huss;                                                  
            text2 "USS";                                                      
            text "Uncorrected SS";                                            
         end;                                                                 
         header = huss;                                                       
         generic;                                                             
      end;                                                                    
                                                                        
       
   define mean;                                                            
         header = "Mean";                                                     
         generic;                                                             
      end;                                                                    
      define sum;                                                             
         header = "Sum";                                                      
         generic;                                                             
      end;                                                                    
      define sumwgt;                                                          
         header = "Sum Wgts";                                                 
         generic;                                                             
      end;                                                                    
      define nmiss;                                                           
         header = "N Miss";                                                   
         generic;                                                             
      end;                                                                    
      define n;                                                               
         header = "N";                                                        
         generic;                                                             
      end;                                                                    
      define range;                                                           
         header = "Range";                                                    
         generic;                                                             
      end;                                                                    
      define max;                                                             
         define header hmax;                                                  
            text2 "Max";                                                      
            text "Maximum";                                                   
         end;                                                                 
         header = hmax;                                                       
         generic;                                                             
      end;                                                                    
      define min;                                                             
         define header hmin;                                                  
            text2 "Min";                                                      
            text "Minimum";                                                   
         end;                                                                 
         header = hmin;                                                       
         generic;                                                             
      end;                                                                    
      define label;                                                           
         header = "Label";                                                    
         id;                                                                  
         generic;                                                             
      end;                                                                    
      define varname;                                                         
         header = "Variable";                                                 
         id;                                                                  
         generic;                                                             
      end;                                                                    
      define ways;                                                            
         header = "Ways";                                                     
         vjust = T;                                                           
         id;                                                                  
      end;                                                                    
      define type;                                                            
         header = "Type";                                                     
         vjust = T;                                                           
         id;                                                                  
      end;                                                                    
      define id;                                                              
         vjust = T;                                                           
         id;                                                                  
         generic;                                                             
      end;  
   define nobs;                                                            
         header = "N Obs";                                                    
         vjust = T;                                                           
         style = {                                                       
            color = green                                                
            };                                                                
            id;                                                                  
         end;                                                                    
      define class;                                                           
         vjust = T;                                                           
         id;                                                                  
         generic;                                                             
         blank_internal_dups;                                                 
      end;                                                                    
      define h;                                                               
         text "Analysis Variable : " one_var_name " " one_var_label;          
         space = 1;                                                           
         just = C;                                                            
         print = one_var;                                                     
         spill_margin;                                                        
      end;                                                                    
      required_space = 5;                                                     
      underline;                                                              
      overline;                                                               
      byline;                                                                 
      use_format_defaults;                                                    
      double_space;                                                           
      split_stack;                                                            
      use_name;                                                               
      order_data;                                                             
      classlevels;                                                            
   end;                                                                       
run; 

Program 2

 Note about code
ods path work.templat (update) sashelp.tmplmst (read);
proc template;                                                                
   define table Base.Summary;                                                 
      notes "Summary table for MEANS and SUMMARY";                            
      dynamic clmpct one_var_name one_var_label one_var;                      
      column class nobs id type ways (varname) (label) (min) (max) (range) (n 
         ) (nmiss) (sumwgt) (sum) (mean) (uss) (css) (var) (stddev) (cv) (    
         stderr) (t) (probt) (lclm) (uclm) (skew) (kurt) (median) (mode) (q1) 
         (q3) (qrange) (p1) (p5) (p10) (p25) (p50) (p75) (p90) (p95) (p99);   
                                                                  
                                                            
      define nobs;                                                            
        style={color=magenta backgroundcolor=white}; 
                                                                        
      end;                                                                    
                                                                 
   end;                                                                       
run;   

ods html file="temp.html";

proc summary data=exprev print;
class Sale_Type;
run;

ods html close; 

HTML Output That Uses the Table Template Base.Summary.

 Note about figure

[HTML Output That Uses the Table Template Base.Summary.]

Base.Summary Table Template Created by the DEFINE TABLE Statement

 Note about figure
proc template;                                                                
   define table Base.Summary / store = WORK.TEMPLAT;                          
      notes "Summary table for MEANS and SUMMARY";                            
      dynamic clmpct one_var_name one_var_label one_var;                      
      column class nobs id type ways (varname) (label) (min)
      (max) (range) (n)(nmiss) (sumwgt) (sum) (mean) (uss) (css)
      (var) (stddev) (cv) (stderr) (t) (probt) (lclm) (uclm) (skew)
      (kurt) (median) (mode) (q1) (q3) (qrange) (p1) (p5) (p10) 
      (p25) (p50) (p75) (p90) (p95) (p99);         
      define nobs;                                                            
         style = {                                                            
            color = green                                                
            };                                                                
      end;                                                                    
   end;                                                                       
run;           

Previous Page | Next Page | Top of Page