ODS and Base Reporting

Build reports by using ODS to create HTML, PDF, RTF, Excel, text reports and more!
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
abcg
Fluorite | Level 6

Hi, I wonder how to change the background color of a text string via ODS PDF. It works at ODS RTF, but I don't know why it does not work at ODS PDF. Here is the code:

 

data aaa;
a=cat('abc',"^{style[backgroundcolor=pink foreground=red]defg}","hi");
output;
a=cat('abc',"^{style[background=pink foreground=red]defg}","hi");
output;
run;

ods escapechar='^';
ods pdf file="test.pdf";ods rtf file="test.pdf";
proc print data=aaa;
run;
ods _all_ close;

The ODS RTF output returns this, and that is what I want: red text with pink background.

 

abcg_0-1623690328098.png

 

But ODS PDF output returns just red text, background color does not change.

 

abcg_1-1623690355431.png

 

Can anyone show me any issue from my code? Thanks!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ
Hi:
Yes, @jimbarbour's choice b is the answer. I always explain it to my students this way when they ask if something is possible (like can I change the page number to the bottom of the page) -- The answer is "It depends on the destination" -- RTF and PDF -- yes; HTML -- No, ODS Excel, yes, but you have to use Microsoft specific field codes to do it.

The way I understand PDF is that PDF "wants" the background color to apply to the entire data cell. So foreground color for part of the string is OK. But background color doesn't work for inline formatting because PDF wants the whole cell to have the same background. It's different for RTF and Word because, well, Microsoft.

Cynthia

View solution in original post

3 REPLIES 3
jimbarbour
Meteorite | Level 14

I ran your code and got the same results.  I used two different means to open the pdf, so I don't think it's your pdf reader that is at issue.

 

The fact that the code works for one ODS destination but not another suggests that one of the following may be true

a) there could be a bug in the SAS software

b) this feature just isn't supported in pdf

 

I don't really know which it is in this case.  @Cynthia_sas seems to know a lot on this subject.  Perhaps if she has time she can weigh in.

 

Jim

Cynthia_sas
SAS Super FREQ
Hi:
Yes, @jimbarbour's choice b is the answer. I always explain it to my students this way when they ask if something is possible (like can I change the page number to the bottom of the page) -- The answer is "It depends on the destination" -- RTF and PDF -- yes; HTML -- No, ODS Excel, yes, but you have to use Microsoft specific field codes to do it.

The way I understand PDF is that PDF "wants" the background color to apply to the entire data cell. So foreground color for part of the string is OK. But background color doesn't work for inline formatting because PDF wants the whole cell to have the same background. It's different for RTF and Word because, well, Microsoft.

Cynthia
jimbarbour
Meteorite | Level 14

Thank you, @Cynthia_sas.  It's about time somebody showed up around here who actually knows what they're talking about...  

 

Jim

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 3 replies
  • 2630 views
  • 3 likes
  • 3 in conversation