BookmarkSubscribeRSS Feed
joseph17
Calcite | Level 5
Hi,

I would like to apply a format to a column such that:
- if it contains "+" then print it red
- if it contains "-" then print it blue
- otherwise print it black

It's supposed to be used to build a title from different columns.

I know that I can include colour formatting in proc report in such way for numeric values:
PROC FORMAT;
value visits 2.54-2.99 = orange 3.02-high = red other = black;
RUN;

Please let me know if you know any solution that solves this problem for text variables (using e.g. regular expressions).

Thanks,
Michal
9 REPLIES 9
NickR
Quartz | Level 8
I'm not sure if this is possible in proc format.

How about in data step?

if index(value,'+') then color='red';
else if index(value,'-') then color='blue';
else color='black';
joseph17
Calcite | Level 5
Thanks for your reply.
Do you mean to add an extra column with color name?
Then the question is - how to apply this later when I would like to use this column value in title statement and would like it to be in a specyfic color format?

e.g.

data _null_;
set myset;
titl4 = "Patient: " || trim(put(subjid,???));
call symput('titl4',titl4);
run;

title4 %trim("titl4");
Peter_C
Rhodochrosite | Level 12
> It's supposed to be used to build a title from
> different columns.

Michal
( aka joseph17)

I am not quite sure what this "title" means...
I think of a column title being the column heading....

since headings can be defined separately from the data it should be possible to derive special headings for each column.

How are you planning that this should be reported?

peterC
chang_y_chung_hotmail_com
Obsidian | Level 7
The TITLE statement has ods format options that work for HTML, RTF, and PRINTER destinations. One of them is the COLOR= option to set the title text color. Below is a macro that returns the option and a quoted text string based on the first character of the title. (It "eats up" the first char if it is either a plus(+) or a minus(-) char.)



It is easy to modify it so that it looks for the plus and minus signs in any place in the title text. But you have to make a design decision on how to handle the title with both the signs in.



   %*-- based on the first char, returns a color= option and quoted title text --*;


   %macro title(str);


      %local ch1 color;


      %let str = %superq(str);


      %if &str= %then %return


 


      %let ch1 = %qsysfunc(first(&str));


      %if &ch1 = %str(+) %then 


         %let color = red;


      %else %if &ch1 = %str(-) %then 


         %let color = blue;


      %else 


         %let color = black;


 


      %if &color ^= black %then %let str = %qsubstr(&str,2);


      


      %unquote(color=&color %qsysfunc(quote(&str)))


   %mend  title;


 


 


   /* check */


   options mprint;


   title %title(+title in red);


   /* on log


   MPRINT(TITLE):   color=red "title in red"


   */

joseph17
Calcite | Level 5
Thank you for this solution - it's almost what I want to get.
I use this TITLE statement in ODS PDF. What I want to get is to highlight only the value that comes from this column, not the whole title. As I mentioned, the title is combined of various columns and I want them to be printed in one line.

My header with titles looks like that:

V1: value1, V2: value2, ... /*title1*/
VN: valueN, VN+1: valueN+1, ... /*title2*/
...

I want, e.g. to print in red only "value2". Is it possible?
deleted_user
Not applicable
Have you thought of using ods escapechar with style options?

ods escapechar='^';

title1 "V1: value1, V2: ^{s value2}, ... ";

should do what you need I think?
Peter_C
Rhodochrosite | Level 12
as a test to place more than one color in a title line, I ran the code
ods pdf file='test.pdf' style=default ;
proc print data= sashelp.class( obs=5) ;
title1 j=l 'test' h=4 j=c c=red 'middle' '-' c=b 'middle2' j=r c=orange 'right' ;
run;
ods pdf close ;
dm 'winexecfile ''test.pdf'' ' ;
This does show centered text 'middle-middle2' with the "middle-" in red and the "middle2" in blue.
J= provides justification (left/center/right) for the strings that follow, until the next J=
I think this should be easy to generate, once what strings need what colors can be defined.
Note that a title can only change between each PROC (or when relevant, between run-groups as in proc gplot, and probably between the reporting statements by PROC SQL).
peterC
joseph17
Calcite | Level 5
This helped!
Thank you very much for this clue.

the code that worked finally is:

ods escapechar='^';
title1 "V1: value1, V2: ^{style [foreground=red] value2}, ... ";

More details can be found here:
http://support.sas.com/documentation/cdl/en/odsug/61723/HTML/default/a002233270.htm

Thank you all for the answers.
Michal
Ksharp
Super User
Are you using proc report to make a traffic light?
[pre]
if findc(visit,'+') then call define(_col_,'style','style={}');
[/pre]



Ksharp

sas-innovate-2024.png

Today is the last day to save with the early bird rate! Register today for just $695 - $100 off the standard rate.

 

Plus, pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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