Build reports by using ODS to create HTML, PDF, RTF, Excel, text reports and more!

Conditional Formatting report using Proc Report

Reply
Frequent Learner
Posts: 1

Conditional Formatting report using Proc Report

[ Edited ]

I am trying to color x-rate based on flag_x value but below code is not working.. please help. sample file attached.


PROC REPORT DATA= FINAL NOWD;
COLUMN HOSPITAL_CODE x_RATE THRESHOLD TARGET MAX FLAG_x;


DEFINE HOSPITAL_CODE / DISPLAY;
DEFINE x_RATE / DISPLAY;
DEFINE THRESHOLD / DISPLAY;
DEFINE TARGET / DISPLAY;
DEFINE MAX / DISPLAY;
DEFINE FLAG_x / DISPLAY;

COMPUTE x_RATE;
IF FLAG_x=1 THEN CALL DEFINE(_COL_,'STYLE','STYLE={BACKGROUND=blue}');
ELSE IF FLAG_x=2 THEN CALL DEFINE(_COL_,'STYLE','STYLE={BACKGROUND=GREEN}');
ELSE IF FLAG_x=3 THEN CALL DEFINE(_COL_,'STYLE','STYLE={BACKGROUND=YELLOW}');
ELSE IF FLAG_x=4 THEN CALL DEFINE(_COL_,'STYLE','STYLE={BACKGROUND=RED}');
ENDCOMP;


RUN;

Respected Advisor
Posts: 3,294

Re: Conditional Formatting report using Proc Report

In the COLUMN statement, FLAG_X must appear before (to the left of) X_RATE.

--
Paige Miller
SAS Super FREQ
Posts: 9,435

Re: Conditional Formatting report using Proc Report

Posted in reply to PaigeMiller

Hi:

  And, if you absolutely need the variable FLAG_X listed as the last item on the report row, then you can use it multiple times on the report. Use it once to the left of X_RATE for highlighting and then use it again with an alias name in the column statement so it will appear in the position you want. In the code below, AGE is used to highlight the SEX column, but it also appears as the last variable on the report row because of using the construction AGE=SHOWLAST in the COLUMN statement to place the alias item at the end of the row.

cynthiause_alias.png

Ask a Question
Discussion stats
  • 2 replies
  • 109 views
  • 0 likes
  • 3 in conversation