- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Dear SAS community,
I've recently started to use proc report and I can't figure out how to change the background color of different line statements. I am using SAS Studio. The code below highlights Acura a light green color and BMW a yellow color. I need my data to look like this where the group make is like a header. The texts line1, line2, line3, and line4 are placeholders that will contain something else.
data test1; set sashelp.cars;
dummy=1;
if make in ("Acura" "BMW");
run;
ods escapechar="^";
proc report data=test1 out=rep1;
columns make model msrp,type dummy;
define make / group noprint;
define model / group ;
define type / across "";
define msrp / display "MSRP";
define dummy / sum noprint;
compute before _page_ / style=[fontsize=13pt just=l];
line "line1";
line "line2";
endcomp;
compute before make / style=[just=left];
length text $100;
if make = "Acura" then
text = " ^{style[font_size=13pt font_weight=bold background=lightgreen]" ||strip(make)|| "}";
if make ="BMW" then
text = " ^{style[font_size=13pt font_weight=bold background=yellow]" ||strip(make)|| "}";
line @0 text $100.;
endcomp;
compute after / style=[fontsize=13pt just=left];
line "line3";
line "line4";
endcomp;
run;
The above code produces the output below.
I want the background of Acura and BMW to look like below except I want them to have different colors. For example, I want Acura to be light green and BMW to be yellow. If I use style(lines) in proc report to change the background, it will also affect the background color of line1, line2, line3, and line4. How can I make my data look like the screenshot below except the make group has different colors? Doing a call define (_row, "style", "style=[background=yellow") does not seem to work. I would also like to know how I can do it if I have more than 2 different groups. I will be ods pdf for this data.
proc report data=test1 out=rep1;
columns make model msrp,type dummy;
define make / group noprint;
define model / group ;
define type / across "";
define msrp / display "MSRP";
define dummy / sum noprint;
compute before _page_ / style=[fontsize=13pt just=l];
line "line1";
line "line2";
endcomp;
compute before make / style=[just=left backgroundcolor=yellow];
length text $100;
if make = "Acura" then
text = " ^{style[font_size=13pt font_weight=bold]" ||strip(make)|| "}";
if make ="BMW" then
text = " ^{style[font_size=13pt font_weight=bold]" ||strip(make)|| "}";
line @0 text $100.;
endcomp;
compute after / style=[fontsize=13pt just=left];
line "line3";
line "line4";
endcomp;
run;
I want Acura to have a light green background color and BMW to have a yellow background color. The background for line1, line2, line3, and line4 should be as it is. Thank you for the help.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
How about this one ?
data test1; set sashelp.cars; dummy=1; if make in ("Acura" "BMW"); run; ods escapechar="^"; option missing=' '; proc report data=test1 out=rep1 nowd; columns make model msrp,type dummy; define make / group noprint; define model / group ; define type / across ""; define msrp / display "MSRP"; define dummy / sum noprint; compute before _page_ / style=[fontsize=13pt just=l]; line "line1"; line "line2"; endcomp; compute after / style=[fontsize=13pt just=left]; line "line3"; line "line4"; endcomp; compute dummy; if _break_='Make' and make='Acura' then do; model=make; call define(_row_,'style','style={font_weight=bold background=lightgreen}'); end; if _break_='Make' and make='BMW' then do; model=make; call define(_row_,'style','style={font_weight=bold background=yellow}'); end; endcomp; break before make/summarize ; run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You need to apply the style to the whole row. I'm not quite sure how you're applying your styles, but this is how I do it when I need to do banding on my reports, by group. In this case, I'm grouping my report by provider and each provider group alternates with lightgrey background. You can replace lightgrey with the hex colour of your choice by specifying it as cx######.
compute after mergedProvider;
I + 1;
endcomp;
compute differential;
if mod(i,2) eq 1
then call define(_row_, "style", "STYLE=[background=lightgrey]");
endcomp;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
How about this one ?
data test1; set sashelp.cars; dummy=1; if make in ("Acura" "BMW"); run; ods escapechar="^"; option missing=' '; proc report data=test1 out=rep1 nowd; columns make model msrp,type dummy; define make / group noprint; define model / group ; define type / across ""; define msrp / display "MSRP"; define dummy / sum noprint; compute before _page_ / style=[fontsize=13pt just=l]; line "line1"; line "line2"; endcomp; compute after / style=[fontsize=13pt just=left]; line "line3"; line "line4"; endcomp; compute dummy; if _break_='Make' and make='Acura' then do; model=make; call define(_row_,'style','style={font_weight=bold background=lightgreen}'); end; if _break_='Make' and make='BMW' then do; model=make; call define(_row_,'style','style={font_weight=bold background=yellow}'); end; endcomp; break before make/summarize ; run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, Ksharp! This is the solution I was looking for.