Hi Experts,
Is it possible to highlight the specific text within a cell in proc report
e.g. if i have text as 'AAA BBB CCC' so i wanted to either highlight 'BBB' alone or just change the font color of only that text. Is it possible, any suggestions.
data have;
txt='AAA BBB CCC';
run;
ods listing close;
ods pdf file="..../sample.pdf";
PROC REPORT DATA=have LS=132 PS=60 SPLIT="/" CENTER style(summary)=Header;
COLUMN txt ;
DEFINE txt / DISPLAY WIDTH=30 SPACING=2 LEFT " " ;
run;
title;
ods pdf close;
ods listing;
Hi:
Good call. You need a compute block unless you're going to add ODS ESCAPECHAR style functions to the actual data. In this example, I just created a new report item and did the manipulation inside a COMPUTE block.
Cynthia
My guess is that you would need a compute block in Proc Report and parse the string to set the attributes for the bits you want highlighted. Anything else is going to have the text properties the same for the entire cell.
Some possibilities might be:
If the position of the text you want to highlight could be treated as the same in each bit of text then split the next into two or three variables and then the single value would be a single cell that could be highlighted with the typical traffic lighting techniques.
Depending on what is needed perhaps a different display approach entirely such as the Report Writing Interface . Any summary calculations would need to be done first.
ODS Text statements though cumbersome would do this but likely not what you want if there are other fields/calculations involved.
Building the string to include native codes to set properties and not relying on strictly ODS style properties. The RAW function used with ODS ESCAPECHAR will insert HTML or RTF codes (not PDF though)
Hi:
Good call. You need a compute block unless you're going to add ODS ESCAPECHAR style functions to the actual data. In this example, I just created a new report item and did the manipulation inside a COMPUTE block.
Cynthia
Thank you @Cynthia_sas, the solution worked.
Also Thank @ballardw for the suggestion of ods escapechar="^".
I tried the ods escapechar="^" option as below and it gave me the expected result.
data have;
txt='AAA BBB CCC';
comment=tranwrd(txt,'BBB','^S={foreground=red}BBB');
comment=tranwrd(comment,'BBB','BBB^S={}');
run;
ods listing close;
ods pdf file="./sample.pdf";
ods escapechar="^";
PROC REPORT DATA=have LS=132 PS=60 SPLIT="/" CENTER style(summary)=Header;
COLUMN comment ;
DEFINE comment / DISPLAY WIDTH=30 SPACING=2 LEFT " " ;
run;
title;
ods pdf close;
ods listing;
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!
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.