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

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.

alfred1_0-1590531619021.png

 

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;

alfred1_2-1590532097411.png

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.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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;

View solution in original post

3 REPLIES 3
Reeza
Super User

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; 
Ksharp
Super User

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;
alfred1
Calcite | Level 5

Thank you, Ksharp! This is the solution I was looking for.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 3 replies
  • 775 views
  • 1 like
  • 3 in conversation