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

Hi,

How can I change the below code so that only the text "Shaded area" has a colored background?  Also, instead of saying "background=white", I'd prefer to say "background=<background color of the current style>", i.e. something like "background=default".

(Obviously, this text is a legend.  Given the design of the report, the best place to print this is in a footnote).

Thanks,

Scott

filename temp temp;

options orientation=portrait nodate nonumber;

ods _all_ close;

ods escapechar = '^';

ods pdf file=temp notoc startpage=no style=SeasidePrinter;

title;

footnote;

footnote7  h=8pt j=l "^S={background=lightgreen}Shaded area^S={background=white} = % change less than -20%";

footnote8  h=8pt j=l "^S={background=lightred}Shaded area^S={background=white} = % change greater than 20%";

footnote10 h=8pt j=l "Date: %sysfunc(today(),date11.)" j=c "Page ^{thispage} of ^{lastpage}";

proc print data=sashelp.class noobs;

run;

ods pdf close;

ods listing;


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

   Having worked with ODS for a while, I have come to accept that the underlying "rules" for each destination are different. (HTML is ruled by W3C specs for how a table is defined and how browser renders an HTML table; RTF is ruled by how Word renders a table and how Microsoft defined a "table" and a "cell"; and PDF is ruled by how Adobe renders a table and how Adobe defines a "table" and a "cell"). The fundamental underlying assumption of RTF is that the output you create can be edited and changed; the underlying assumption of PDF is that the output you create is document that contains the way the output would look -exactly- as if you had sent it to a printer -- this means that the PDF file cannot easily be edited or changed unless you have Adobe software of some type. So it doesn't surprise me that the same technique can produce different results in different destinations. Generally, a single cell within a table can only have one background color. Some destinations allow single words within a cell to have different background colors (RTF, HTML). Others don't  If you switched to showing the foreground color as your indicator then you might have better luck. But I know, changing the font of words, isn't the look you want.

  Since ODS LAYOUT is experimental, I'm not sure whether you could use the technique the way you want. That would be a question for Tech Support.

  To some extent, the words "Shaded area" inside each rectangle of color, are redundant and unnecessary, so if you could use the Webdings font (or some other fonts with rectangles drawn in the font), then you could use the COLOR or FOREGROUND attribute to change the foreground color of the rectangle. And you could do what you want in a footnote (see screenshot). So if you can lose the "Shaded area" text, in the Webdings font, the letter 'g' is a boxy rectangle.

cynthia

footnote7  h=8pt j=l "^{style[color=lightgreen font_face='Webdings' font_size=20pt]g} ^{style[font_size=8pt color=black]= % change less than -20%}";
footnote8  h=8pt j=l "^{style[color=lightred   font_face='Webdings' font_size=20pt]g} ^{style[font_size=8pt color=black]= % change greater than 20%}";

footnote10 h=8pt j=l "Date: %sysfunc(today(),date11.)" j=c "Page ^{thispage} of ^{lastpage}";


using_webdings.png

View solution in original post

4 REPLIES 4
Cynthia_sas
SAS Super FREQ

Hi:

  What version of SAS are you running? The ESCAPECHAR syntax that you are using is the "older" syntax for altering "in-line" styles, such as used in SAS 8.2 and 9.0 and 9.1. If you are running SAS 9.2 or higher, there is a slightly different syntax with a usage that is more like a function. Footnote #8 uses the older syntax and Footnote #7 uses the newer syntax.  If you look at the 2 revised FOOTNOTE statements below, you will see the difference in usage.

footnote7 "^{style[background=lightgreen]Shaded area} ^{style[background=_undef_]= % change less than -20%}";

footnote8 "^S={background=lightred}Shaded area^S={} ^S={background=_undef_}= % change greater than 20%";

  (I took out some of your footnote options to make the lines only show the footnote string.)

  Generally to use some attribute from the style, you would use _UNDEF_ as the value for the attribute. However, you're not out of the woods yet. Even with the new syntax, if you look at the attached screenshot of output, either old or new syntax, works best in HTML. As you can see, footnote 7 works for RTF, but footnote 8 doesn't work for RTF. But, with PDF, neither method gives the desired result.

  Can you create an RTF file and then distill a PDF file from the RTF file? Or create an HTML file and then distill the HTML to PDF and have Adobe add the page numbers (since the {thispage} and {lastpage} don't work with HTML)?

  When you say that you are creating a LEGEND, I wonder whether you are actually going to use one of the graphic procedures instead of PROC PRINT for your final report. If so, there are other ways to have a common legend at the bottom of the page when you use SAS/GRAPH. For an example of a common legend using SAS/GRAPH and GREPLAY, see this Tech Support note:

http://support.sas.com/kb/24/945.html

cynthia


corrected_shade_footnote_diff_dest.png
ScottBass
Rhodochrosite | Level 12

Hi Cynthia,

Thanks for the reply.  Much appreciated.

I'm using SAS 9.2 on Windows.  I got the in-line style syntax from the first SGF paper that appeared to meet my needs ;-).  I've seen both formatting styles; now I know that the ^S= style is deprecated.

The legend is to explain the meaning of traffic highlighting in a PROC REPORT output.  Writing to an RTF file and distilling a PDF file from that is not an option.  The PDF file is created from a stored process, then emailed to the user.

It's a (minor) bummer I can't shade just the portion of text I want in a PDF file output, and it seems strange to me that identical code gives different results between HTML, RTF, and PDF outputs.  Or at least different in the characteristics shown.

However, this gives somewhat acceptable results:

footnote7  h=8pt j=l "^{style[background=lightgreen]Shaded area} ^{style[background=_undef_]= % change less than -20%}" j=c " ";

footnote8  h=8pt j=l "^{style[background=lightred]Shaded area} ^{style[background=_undef_]= % change greater than 20%}" j=c " ";


Changing tack...another possible option is to use ODS layout to print the legend in the upper right corner of the report.  However, can ODS layout create an overlapping region, or a "region within a region"?  What I mean by this is, I want the entire page available for the PROC REPORT output.  I want the output centered, but the width of the data is such that there will be whitespace on the right (and left) of the page.  If I can overlay a small "box" in the upper right corner, I could put the legend there.  If the layout for the legend box pushed the page down or un-centered the page, this would not be an option.

The legend in the upper right corner was actually the format for the old Hyperion report on which I'm basing my re-write.  However, I thought using footnotes for the legend would be an acceptable change for the end user of the report.

Thanks again,

Scott


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
Cynthia_sas
SAS Super FREQ

Hi:

   Having worked with ODS for a while, I have come to accept that the underlying "rules" for each destination are different. (HTML is ruled by W3C specs for how a table is defined and how browser renders an HTML table; RTF is ruled by how Word renders a table and how Microsoft defined a "table" and a "cell"; and PDF is ruled by how Adobe renders a table and how Adobe defines a "table" and a "cell"). The fundamental underlying assumption of RTF is that the output you create can be edited and changed; the underlying assumption of PDF is that the output you create is document that contains the way the output would look -exactly- as if you had sent it to a printer -- this means that the PDF file cannot easily be edited or changed unless you have Adobe software of some type. So it doesn't surprise me that the same technique can produce different results in different destinations. Generally, a single cell within a table can only have one background color. Some destinations allow single words within a cell to have different background colors (RTF, HTML). Others don't  If you switched to showing the foreground color as your indicator then you might have better luck. But I know, changing the font of words, isn't the look you want.

  Since ODS LAYOUT is experimental, I'm not sure whether you could use the technique the way you want. That would be a question for Tech Support.

  To some extent, the words "Shaded area" inside each rectangle of color, are redundant and unnecessary, so if you could use the Webdings font (or some other fonts with rectangles drawn in the font), then you could use the COLOR or FOREGROUND attribute to change the foreground color of the rectangle. And you could do what you want in a footnote (see screenshot). So if you can lose the "Shaded area" text, in the Webdings font, the letter 'g' is a boxy rectangle.

cynthia

footnote7  h=8pt j=l "^{style[color=lightgreen font_face='Webdings' font_size=20pt]g} ^{style[font_size=8pt color=black]= % change less than -20%}";
footnote8  h=8pt j=l "^{style[color=lightred   font_face='Webdings' font_size=20pt]g} ^{style[font_size=8pt color=black]= % change greater than 20%}";

footnote10 h=8pt j=l "Date: %sysfunc(today(),date11.)" j=c "Page ^{thispage} of ^{lastpage}";


using_webdings.png
ScottBass
Rhodochrosite | Level 12

Hi Cynthia,

Yeah, I know HTML, RTF, and PDF will have different outputs from the same code.  I just meant it seemed strange that the footnote would have differing characteristics between the three output types.

Anyway, your approach is very innovative, and one I would not have thought of.  I'm using your "webdings" approach in my final report.

Thanks for the help,

Scott


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 3353 views
  • 0 likes
  • 2 in conversation