Programs That Illustrate Inheritance

Overview

The programs in this section show the PROC TEMPLATE steps that were used in Understanding Styles, Style Elements, and Style Attributes to illustrate inheritance in style definitions. These programs also show the SAS code that uses the style definitions.

Using the FROM option

This program generates the HTML output in the section Using the FROM Option.
  • This version of the code uses the FROM option in the STYLE statement to create the Colors style element in the Concepts.Style2 style definition.
    ods path sashelp.tmplmst(read) sasuser.templat(update);
    title; 
    options nodate pageno=1 linesize=72 pagesize=60; 
    data test;
       input country $ 1-13 grain $ 15-18 kilotons;
       datalines; 
    Brazil        Rice   10035 
    China         Rice   190100 
    India         Rice   120012 
    Indonesia     Rice   51165
    United States Rice   7771 
    ;
    
    proc template;
       define table mytable; 
          column x y z w; 
          define x; 
             style=celldatasimple; 
             dataname=country; 
             header='Country'; 
          end; 
          define y; 
               style=celldataemphasis; 
               dataname=grain; 
               header='Grain'; 
          end; 
          define z; 
             style=celldatalarge; 
             dataname=kilotons; 
             header='Kilotons'; 
          end;
          define w;
             style=celldatasmall;
             dataname=kilotons;
             header='Kilotons';
          end; 
       end; 
    run; 
    
    proc template; 
       /* to ensure a fresh start with the styles */
       delete concepts.style1;
       delete concepts.style2; 
    run;
    
    proc template; 
       define style concepts.style1; 
          style colors / 
             'default'=white
             'fancy'=very light vivid blue
             'medium'=red ;
          style celldatasimple /
             fontfamily=arial 
             backgroundcolor=colors('fancy')
             color=colors('default');
          style celldataemphasis from celldatasimple /
             color=colors('medium')
             fontstyle=italic;
          style celldatalarge from celldataemphasis /
             fontweight=bold
             fontsize=3;
       end; 
    run; 
    
    proc template;
       define style concepts.style2;
          parent=concepts.style1;  
          style colors from colors/
             'dark'=dark blue;  
          style celldataemphasis from celldataemphasis /
             backgroundcolor=white;
          style celldatasmall from celldatalarge /
             fontsize=5
             color=colors('dark') 
             backgroundcolor=colors('medium');  
       end;
    run;
    ods html body='display1-body.htm' 
             style=concepts.style2; 
    data _null_; 
       set test; 
       file print ods=(template='mytable'); 
       put _ods_; 
    run; 
    ods html close;
  • This version of the code does not use the FROM option in the STYLE statement to create the Colors style element in the Concepts.Style2 style definition.
    ods path sashelp.tmplmst(read) sasuser.templat(update);
    title; 
    options nodate pageno=1 linesize=72 pagesize=60; 
    data test;
       input country $ 1-13 grain $ 15-18 kilotons;
       datalines; 
    Brazil        Rice   10035 
    China         Rice   190100 
    India         Rice   120012 
    Indonesia     Rice   51165
    United States Rice   7771 
    ;
    
    proc template;
       define table mytable; 
          column x y z w; 
          define x; 
             style=celldatasimple; 
             dataname=country; 
             header='Country'; 
          end; 
          define y; 
               style=celldataemphasis; 
               dataname=grain; 
               header='Grain'; 
          end; 
          define z; 
             style=celldatalarge; 
             dataname=kilotons; 
             header='Kilotons'; 
          end;
          define w;
             style=celldatasmall;
             dataname=kilotons;
             header='Kilotons';
          end; 
       end; 
    run; 
    
    proc template; 
       /* to ensure a fresh start with the styles */
       delete concepts.style1;
       delete concepts.style2; 
    run;
    
    proc template; 
       define style concepts.style1; 
          style colors / 
             'default'=white
             'fancy'=very light vivid blue
             'medium'=red ;
          style celldatasimple /
             fontfamily=arial 
             backgroundcolor=colors('fancy')
             color=colors('default');
          style celldataemphasis from celldatasimple /
             color=colors('medium')
             fontstyle=italic;
          style celldatalarge from celldataemphasis /
             fontweight=bold
             fontsize=3;
       end; 
    run; 
    
    proc template;
       define style concepts.style2;
          parent=concepts.style1;  
          style colors /
             'dark'=dark blue;  
          style celldataemphasis from celldataemphasis /
             backgroundcolor=white;
          style celldatasmall from celldatalarge /
             fontsize=5
             color=colors('dark') 
             backgroundcolor=colors('medium');  
       end;
    run;
    ods html body='display1-body.htm' 
             style=concepts.style2; 
    data _null_; 
       set test; 
       file print ods=(template='mytable'); 
       put _ods_; 
    run; 
    ods html close;

Inheritance Compatibility Across SAS Versions

This program generates the HTML output in the section Inheritance Compatibility across Versions.
  • This version of the code uses SAS 9.2 names for tyle attributes supplied by SAS.
    ods path sashelp.tmplmst(read) sasuser.templat(update);
    title; 
    options nodate pageno=1 linesize=72 pagesize=60; 
    data test;
       input country $ 1-13 grain $ 15-18 kilotons;
       datalines; 
    Brazil        Rice   10035 
    China         Rice   190100 
    India         Rice   120012 
    Indonesia     Rice   51165
    United States Rice   7771 
    ;
    
    proc template;
       define table mytable; 
          column x y z w; 
          define x; 
             style=celldatasimple; 
             dataname=country; 
             header='Country'; 
          end; 
          define y; 
               style=celldataemphasis; 
               dataname=grain; 
               header='Grain'; 
          end; 
          define z; 
             style=celldatalarge; 
             dataname=kilotons; 
             header='Kilotons'; 
          end;
          define w;
             style=celldatasmall;
             dataname=kilotons;
             header='Kilotons';
          end; 
       end; 
    run; 
    
    proc template; 
       /* to ensure a fresh start with the styles */
       delete concepts.style1;
       delete concepts.style2; 
    run;
    
    proc template; 
       define style concepts.style1; 
          style celldatasimple /
             fontfamily=arial 
             backgroundcolor=very light vivid blue
             color=white;
          style celldataemphasis from celldatasimple /
             color=red
             fontstyle=italic;
          style celldatalarge from celldataemphasis /
             fontweight=bold
             fontsize=5;
       end; 
    run; 
    
    proc template;
       define style concepts.style2;
          parent=concepts.style1;
          style celldataemphasis from celldataemphasis /
             backgroundcolor=yellow;
          style celldatasmall from celldatalarge /
             fontsize=2;
       end;
    
    ods html body='display1-body.htm' 
             style=concepts.style2; 
    data _null_; 
       set test; 
       file print ods=(template='mytable'); 
       put _ods_; 
    run; 
    ods html close;
  • This version of the code uses SAS 9.1 names for style attributes that are supplied by SAS.
    ods path sashelp.tmplmst(read) sasuser.templat(update);
    title; 
    options nodate pageno=1 linesize=72 pagesize=60; 
    data test;
       input country $ 1-13 grain $ 15-18 kilotons;
       datalines; 
    Brazil        Rice   10035 
    China         Rice   190100 
    India         Rice   120012 
    Indonesia     Rice   51165
    United States Rice   7771 
    ;
    
    proc template;
       define table mytable; 
          column x y z w; 
          define x; 
             style=celldatasimple; 
             dataname=country; 
             header='Country'; 
          end; 
          define y; 
               style=celldataemphasis; 
               dataname=grain; 
               header='Grain'; 
          end; 
          define z; 
             style=celldatalarge; 
             dataname=kilotons; 
             header='Kilotons'; 
          end;
          define w;
             style=celldatasmall;
             dataname=kilotons;
             header='Kilotons';
          end; 
       end; 
    run; 
    
    proc template; 
       /* to ensure a fresh start with the styles */
       delete concepts.style1;
       delete concepts.style2; 
    run;
    
    proc template; 
       define style concepts.style1; 
          style celldatasimple /
             fontface=arial 
             background=very light vivid blue
             foreground=white;
          style celldataemphasis from celldatasimple /
             foreground=red
             fontstyle=italic;
          style celldatalarge from celldataemphasis /
             fontweight=bold
             fontsize=5;
       end; 
    run; 
    
    proc template;
       define style concepts.style2;
          parent=concepts.style1;
          style celldataemphasis from celldataemphasis /
             background=yellow;
          style celldatasmall from celldatalarge /
             fontsize=2;
       end;
    
    ods html body='display1-body.htm' 
             style=concepts.style2; 
    data _null_; 
       set test; 
       file print ods=(template='mytable'); 
       put _ods_; 
    run; 
    ods html close;