BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
esl37
Calcite | Level 5

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;


1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

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

4 REPLIES 4
ballardw
Super User

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

Cynthia_sas
SAS Super FREQ


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

Cynthia_sas
SAS Super FREQ

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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