Help using Base SAS procedures

proc template --- give different background color to different columns in a table

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

proc template --- give different background color to different columns in a table

Hi,

I need to give different background colors to different columns in a table by using proc template. Does anyone have experience on it?

I tried to use below codes. But the program only changed the backgrounds of the body of the table. The background color of the headers is still the same.

proc template;

/*--------------------------*/

/* Table definition

/*--------------------------*/

define table mytable;

  column a b c ;

center=on;

/*-------------------------------------*/

/* Set up the headers of each variable

/*-------------------------------------*/ 

define a ;

  header='AAA' style=[background=red]

  just=center;

end;

define a ;

  header='BBB' style=[background=blue]

  just=center;

end;

define a ;

  header='CCC' style=[background=yellow]

  just=center;

end;

run;



Accepted Solutions
Solution
‎03-06-2014 07:47 PM
SAS Super FREQ
Posts: 8,743

Re: proc template --- give different background color to different columns in a table

Hi, something bothered me about the OP code. There weren't enough END statements -- so the originally posted code should be getting an error:

      

ERROR: Parse environments were left open. You might be missing an END statement.

   Had a chance to modify the example.

Cynthia

ods path work.tmp(update) sasuser.templat(update)
         sashelp.tmplmst(read);
  
** you can define header text and style in the define block;
** for the column;
** then the simple style= in the define block refers to the datacells;
** and cellstyle ...as refers to the data cells;
proc template;
define table mytable;
  column a b c ;
  center=on;
   define a ;
    define header ahd;
       text 'AAA';
       style={background=red};
    end;
    header=ahd;
    style={background=pink};
    just=center;
  end;
     
  define b ;
    define header bhd;
      text 'BBB';
      style={background=blue};
    end;
     header=bhd;
     cellstyle _val_ le 3 as [background=lightgreen],
              _val_ le 5 as {background=lightblue},
              _val_ ge 6 as {background=graycc foreground=red font_weight=bold};
     just=center;
  end;
  
  define c ;
    define header chd;
      text 'CCC';
      style={background=yellow};
    end;
    header=chd;
    style=[background=lightyellow]
    just=center;
  end;
end;
run;
 
ods listing close;
   
ods html file='c:\temp\maketable.html';
data _null_;
set sashelp.class;
  keep  a b c;
  a = name;
  b= age - 10;
  c=height*weight;
  file print ods=(template='mytable');
  put _ods_;
run;
ods html close;



changing_header_and_column_in_table_template.png

View solution in original post


All Replies
Super User
Posts: 10,500

Re: proc template --- give different background color to different columns in a table

I see repeated "Define A" statements, not a Define header. Also you may need a Define Column.

SAS Super FREQ
Posts: 8,743

Re: proc template --- give different background color to different columns in a table


You are correct, slightly different syntax is needed to style a whole column vs the style for a header. This paper shows some of the techniques, at least enough to get the OP started.

http://www2.sas.com/proceedings/sugi30/088-30.pdf

cynthia

Solution
‎03-06-2014 07:47 PM
SAS Super FREQ
Posts: 8,743

Re: proc template --- give different background color to different columns in a table

Hi, something bothered me about the OP code. There weren't enough END statements -- so the originally posted code should be getting an error:

      

ERROR: Parse environments were left open. You might be missing an END statement.

   Had a chance to modify the example.

Cynthia

ods path work.tmp(update) sasuser.templat(update)
         sashelp.tmplmst(read);
  
** you can define header text and style in the define block;
** for the column;
** then the simple style= in the define block refers to the datacells;
** and cellstyle ...as refers to the data cells;
proc template;
define table mytable;
  column a b c ;
  center=on;
   define a ;
    define header ahd;
       text 'AAA';
       style={background=red};
    end;
    header=ahd;
    style={background=pink};
    just=center;
  end;
     
  define b ;
    define header bhd;
      text 'BBB';
      style={background=blue};
    end;
     header=bhd;
     cellstyle _val_ le 3 as [background=lightgreen],
              _val_ le 5 as {background=lightblue},
              _val_ ge 6 as {background=graycc foreground=red font_weight=bold};
     just=center;
  end;
  
  define c ;
    define header chd;
      text 'CCC';
      style={background=yellow};
    end;
    header=chd;
    style=[background=lightyellow]
    just=center;
  end;
end;
run;
 
ods listing close;
   
ods html file='c:\temp\maketable.html';
data _null_;
set sashelp.class;
  keep  a b c;
  a = name;
  b= age - 10;
  c=height*weight;
  file print ods=(template='mytable');
  put _ods_;
run;
ods html close;



changing_header_and_column_in_table_template.png
New Contributor
Posts: 4

Re: proc template --- give different background color to different columns in a table

Thank you Cynthia! It works :-)

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 523 views
  • 0 likes
  • 3 in conversation