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

Good morning,

I am trying to create the report and higlight one field based on another field meaning. It is similar to what I found in SAS communiy:

 

proc report nowd data=sashelp.class;
col name sex age weight height;

compute height;
if sex='F' then do;
call define(_col_,"style","style={background = pink}");
end;
endcomp;
run;

 

But the thing is if you use, let's say, Weight instead of Sex field in a compute block - it doesn't work!

 

proc report nowd data=sashelp.class;;
col name sex age weight height;

compute height;
if weight>100 then do;
call define(_col_,"style","style={background = pink}");
end;
endcomp;
run;

 

In my data, I am creating an additional field in dataset and after that I am trying to use it as an indicator to highlight the other filed. Like,

data test;
set sashelp.class;
letter = substr(name,1,1);
run;

 

proc report nowd data=test;
col name sex age weight height letter;

compute height;
if letter="A" then do;
call define(_col_,"style","style={background = pink}");
end;
endcomp;
run;

 

This code again doesn't give me desired result. Can somebody give me a hint WHY?

1 ACCEPTED SOLUTION

Accepted Solutions
ThierryHerrie
Obsidian | Level 7

You're welcome.

The second example works if you show Height and Letter in the col definition

proc report nowd data=test;
  col name sex age weight letter height ; 

  compute height;
    if letter="A" then do;
      call define(_col_,"style","style={background = pink}");
    end;
  endcomp;
run;

View solution in original post

7 REPLIES 7
ThierryHerrie
Obsidian | Level 7

When you refer to a numeric field, you have to add ".sum" to make it work. For example:

proc report nowd data=sashelp.class;;
  col name sex age weight height; 

  compute height;
    if weight.sum>100 then do;
      call define(_col_,"style","style={background = pink}");
    end;
  endcomp;
run;
OLevin
Fluorite | Level 6

Thank you very much, Thierry- with numeric value it now works! Do you have any solution for the second example, when I added field to the sas dataset and after that trying to use it in compute block? It is string format (letter). What can I do here in order to make it work?

ThierryHerrie
Obsidian | Level 7

You're welcome.

The second example works if you show Height and Letter in the col definition

proc report nowd data=test;
  col name sex age weight letter height ; 

  compute height;
    if letter="A" then do;
      call define(_col_,"style","style={background = pink}");
    end;
  endcomp;
run;
OLevin
Fluorite | Level 6

I was wondering, why my example didn't work, because I showed both fields in col definition. But the trick is to show created field (in my case it is Letter) before Hight. And it works now! Smiley Happy Great! Thank you so much!!!!

ThierryHerrie
Obsidian | Level 7
Sorry, I made a typo. Instead of "show" I meant "swap" 🙂
ballardw
Super User

@OLevin wrote:

I was wondering, why my example didn't work, because I showed both fields in col definition. But the trick is to show created field (in my case it is Letter) before Hight. And it works now! Smiley Happy Great! Thank you so much!!!!


A general rule with proc report is that the result table is built from left to right. So a calculated field can't reference the value of a column further to the right to set current cell properties or values because that cell has not been built yet.

So in:

proc report nowd data=test;
col name sex age weight height letter; 

compute height;
if letter="A" then do;
call define(_col_,"style","style={background = pink}");
end;
endcomp;
run;

since the column order has LETTER to the right of HEIGHT the value of letter is considered undefined for setting column height properties.

OLevin
Fluorite | Level 6
It is a very helpful information! Thank you very much, ballardw.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1798 views
  • 2 likes
  • 3 in conversation