Hello
I want to create proc report that just display columns and color cells in following rule:
If column x=1 then value in cell under column x get color background
If column w=1 then value in cell under column w get color background
and so on
Why I don't see any color in my results??
data have;
input custId branchId x w z r t q ;
cards;
123456 111 0 0 1 0 0 1
;
Run;
proc report data=have;
column
custId
branchId
x
w
z
r
t
q
;
define custId/display;
define branchId/display;
define x/display;
define w/display;
define z/display;
define r/display;
define t/display;
define q/display;
COMPUTE x;
IF _COL_=1 then do;
CALL DEFINE(x, "style", "STYLE=[BACKGROUND=MISTYROSE]");
end;
ENDCOMP;
COMPUTE w;
IF _COL_=1 then do;
CALL DEFINE(w, "style", "STYLE=[BACKGROUND=MISTYROSE]");
end;
ENDCOMP;
COMPUTE z;
IF _COL_=1 then do;
CALL DEFINE(z, "style", "STYLE=[BACKGROUND=MISTYROSE]");
end;
ENDCOMP;
COMPUTE r;
IF _COL_=1 then do;
CALL DEFINE(r, "style", "STYLE=[BACKGROUND=MISTYROSE]");
end;
ENDCOMP;
COMPUTE t;
IF _COL_=1 then do;
CALL DEFINE(t, "style", "STYLE=[BACKGROUND=MISTYROSE]");
end;
ENDCOMP;
COMPUTE q;
IF _COL_=1 then do;
CALL DEFINE(q, "style", "STYLE=[BACKGROUND=MISTYROSE]");
end;
ENDCOMP;
Run;
Your syntax is not correct and MISTYROSE doesn't seem to be a color on my system.
data have;
input custId branchId x w z r t q ;
cards;
123456 111 0 0 1 0 0 1
123456 111 1 0 1 0 0 1
123456 111 0 1 1 0 0 1
;
Run;
proc report data=have;
column custId branchId x w z r t q;
define custId/display;
define branchId/display;
define x/display;
define w/display;
define z/display;
define r/display;
define t/display;
define q/display;
COMPUTE x;
IF x=1 then do;
CALL DEFINE(_col_, "style", "STYLE=[BACKGROUND=pink]");
end;
ENDCOMP;
COMPUTE w;
IF w=1 then do;
CALL DEFINE(_col_, "style", "STYLE=[BACKGROUND=lightblue]");
end;
ENDCOMP;
COMPUTE z;
IF z=1 then do;
CALL DEFINE(_col_, "style", "STYLE=[BACKGROUND=lightgreen]");
end;
ENDCOMP;
Run;
Your syntax is not correct and MISTYROSE doesn't seem to be a color on my system.
data have;
input custId branchId x w z r t q ;
cards;
123456 111 0 0 1 0 0 1
123456 111 1 0 1 0 0 1
123456 111 0 1 1 0 0 1
;
Run;
proc report data=have;
column custId branchId x w z r t q;
define custId/display;
define branchId/display;
define x/display;
define w/display;
define z/display;
define r/display;
define t/display;
define q/display;
COMPUTE x;
IF x=1 then do;
CALL DEFINE(_col_, "style", "STYLE=[BACKGROUND=pink]");
end;
ENDCOMP;
COMPUTE w;
IF w=1 then do;
CALL DEFINE(_col_, "style", "STYLE=[BACKGROUND=lightblue]");
end;
ENDCOMP;
COMPUTE z;
IF z=1 then do;
CALL DEFINE(_col_, "style", "STYLE=[BACKGROUND=lightgreen]");
end;
ENDCOMP;
Run;
If you have multiple variables whose value and desired background color are identical it can be worth creating a custom format and using that in the Define statement for those variables instead of using compute blocks.
Note than any dataset containing data used to provide values that change appearance should include observations that do not display that characteristic (i.e. provide more observations ) so the code written for a solution has a chance of showing where the display change shouldn't occur and doesn't. Note that the alternate set that @data_null__ provides such.
Example:
data have; input custId branchId x w z r t q ; cards; 123456 111 0 0 1 0 0 1 123456 111 1 0 1 0 0 1 123456 111 0 1 1 0 0 1 ; Run; proc format ; value color_ones 1='Pink' ; run; proc report data=have; column custId branchId x w z r t q; define custId/display; define branchId/display; define x/display style=[background= color_ones.]; define w/display style=[background= color_ones.]; define z/display style=[background= color_ones.]; define r/display style=[background= color_ones.]; define t/display style=[background= color_ones.]; define q/display style=[background= color_ones.]; run;
Note that one of the strong advantages of the format approach is that when your boss comes in says "Show the values of 2 as greeen" you only need to change ONE line in the program: add 2='green' to the format definition. I know this data doesn't have any values of 2 but are you sure that will not change in the future. Or if the boss says some of the variables should use a different color, then create similar format with the new color and change the name in the Define statement.
You can address multiple display characteristics with this approach such a border line colors or widths, font or text weight, most of the items that can be addressed with a style option in a define statement.
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.
Ready to level-up your skills? Choose your own adventure.