BookmarkSubscribeRSS Feed
ChrisNZ
Tourmaline | Level 20

Hi,

In the code below, the change in row background style seems to change the other style attributes too (the first column is no longer bold). Why is that?

Also, how can I reestablish the first column's style (I'd rather avoid listing all the columns in the IF test and use _ROW_ instead)?

 

proc report data=SASHELP.CLASS(where=(AGE>13)) nowd ;
  columns OBS NAME ;
  define OBS / computed format=2. '#' style(column)=header;
  compute NAME;
    _OBS_ + 1;
    OBS = _OBS_; 

   * Attempt to only alter the background of some lines ;
   * if NAME=:'J' then call define(_ROW_,'style','style=[background=aliceblue]');

   * Attempt to restore column 1 ;
   * call define('_C1_','style','style=header');

  endcomp;
run; 

Capture.PNG

 

 

 

6 REPLIES 6
andreas_lds
Jade | Level 19

SAS generated this:

<tr>
<th class="r header" scope="col">3</th>
<td class="data">Henry</td>
</tr>
<tr>
<td class="r data" style="background-color: #f0f8ff">4</td>
<td class="data" style="background-color: #f0f8ff">Janet</td>
</tr>

I can't see a reason to replace "header" with "data", seems to be a bug (or very special feature), unfortunately this happens in HTML, RTF and PDF. So it doesn't look like something happening by coincidence.

 

Maybe @Cynthia_sas has an idea.

Ksharp
Super User

Chris,

It looks like you need adjust it by hand . hmm.

 

proc report data=SASHELP.CLASS(where=(AGE>13)) nowd ;
  columns OBS NAME ;
  define OBS / computed format=2. '#' style(column)={ backgroundcolor=cxedf2f9 fontweight=bold };
  compute NAME;
    _OBS_ + 1;
    OBS = _OBS_; 

   * Attempt to only alter the background of some lines ;
    if NAME=:'J' then call define(_ROW_,'style','style=[background=aliceblue]');

   * Attempt to restore column 1 ;
   * call define('_C1_','style','style=header');

  endcomp;

run; 
Cynthia_sas
SAS Super FREQ

Hi:

  It might be easier to understand if you set different colors to see what wins:

call_define_wins.png

 

First, the overall style template sets style attributes, in this case HTMLBLUE The class attributes for the STYLE section in the HTML are set here.. Then, DEFINE for OBS overrides what is in the STYLE template for that variable (OBS would usually be styled with the DATA element.) Then, what you have in the CALL DEFINE wins out in the end and overrides what is in the <TR> tags for the J rows. If you want to see header in the class attribute for the OBS and the NAME, then you have to code the CALL DEFINE as I show.

 

Basically, what you are coding in CALL DEFINE is going to win out over everything else in the row.

 

Cynthia

ChrisNZ
Tourmaline | Level 20

@Cynthia_sas 

> Basically, what you are coding in CALL DEFINE is going to win out over everything else in the row.

But I am only coding the background, not the font weight.

 

>Since I said to start from the Header element....

Even changing the data element only changes the header column:

      if NAME=:'J' then call define(_ROW_,'style','style=data[background=aliceblue]');

I tried 

      call define('_C1_','style','style=data[header]');

to recover the style in C1, but SAS spits out scary errors.

 

I guess the way to achieve my desired result for now is to set the background color column by column.

This what I'll use unless something better comes:

     %macro loop; %local i; %do i=2 %to 10;
       if ... then call define("_C&i._",'style','style=data[background=aliceblue]');
      %end; %mend;%loop;   

Also, wasn't there a way to set column/row style override?

 

Thank you all!

ChrisNZ
Tourmaline | Level 20

@Ksharp If I set the details by hand, the result is only valid with the current definition of the current style. Not ideal. 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 6 replies
  • 1120 views
  • 0 likes
  • 4 in conversation