Proc Report - Highlighting one whole row by certain criteria

Reply
Contributor
Posts: 30

Proc Report - Highlighting one whole row by certain criteria

Hello,

I am trying to create a report where I would like one row, specifically the row that contains the missing observations, to be highlighted a different color than all the other rows.  I had thought that I had a solution, however I continually get an error message saying that the "Statement is not valid or it is used out of proper order."  Any help you can provide me with would be greatly appreciated.

The code:


TITLE "Birth Weight by Maternal Race / Ethnicity";

PROC REPORT DATA = bw_all2 NOWD STYLE(HEADER)=[BACKGROUND=LIGHTBLUE];

     COLUMN bwcat miss black white hispanic other total;

     DEFINE bwcat / "Birth Weight Category" ORDER CENTER FORMAT=cat.;

     DEFINE miss / "Missing" DISPLAY CENTER;

     DEFINE black / "African American" DISPLAY CENTER;

     DEFINE white / "Caucasian" DISPLAY CENTER;

     DEFINE other / "Other" DISPLAY CENTER;

     DEFINE total / "Total" DISPLAY CENTER:

     COMPUTE bwcat;

          IF bwcat = 1 THEN CALL DEFINE (_ROW_,"style","Style=[BACKGROUND=LIGHTGREY]");

     ENDCOMP;

RUN;

Super Contributor
Posts: 543

Re: Proc Report - Highlighting one whole row by certain criteria

So, in your code, bwcat = 1 means that bwcat is missing?

When I ran this little piece of code (see below) it worked.

data temp;

set sashelp.class;

if sex = "M" then sex = "";

run;

ods pdf file = "&file_path.\my_file.pdf";

TITLE "No title";

PROC REPORT DATA = temp NOWD STYLE(HEADER)=[BACKGROUND=LIGHTBLUE];

column sex ;

     COMPUTE sex;

          IF sex = "" then call define (_ROW_,"style","Style=[BACKGROUND=red]");

     ENDCOMP;

RUN;

ods pdf close;

So...I wonder what is wrong...?

Anca.

Contributor
Posts: 30

Re: Proc Report - Highlighting one whole row by certain criteria

Thank you Anca,

For some reason when I was specifying that I wanted to change a _ROW_ it was not working.  But I deleted that line of code, rewrote it and now it seems to work okay.  I find it very strange.  There must have been a mysterious unknown typo that I could not find.

Super Contributor
Posts: 543

Re: Proc Report - Highlighting one whole row by certain criteria

If you copied that line from some PDF file or what not, sometimes hidden characters are in there that SAS won't know what to do with it.

Smiley Happy

Super Contributor
Posts: 339

Re: Proc Report - Highlighting one whole row by certain criteria

Could you post your error log? The following code inspired by yours works for me...

ods pdf file="c:\test.pdf";

proc report data=sashelp.heart(obs=20) NOWD STYLE(HEADER)=[BACKGROUND=LIGHTBLUE];

     column status ageatdeath;

     define status / "test column1" ORDER CENTER;

     define ageatdeath / "test missing formating" DISPLAY CENTER;

     compute ageatdeath;

          if ageatdeath=. then call define(_ROW_, "style", "style=[BACKGROUND=LIGHTGREY]");

     endcomp;

run;

ods pdf close;

P.S. if you copy pasted your code here, I shall mention that the last DEFINE line ends with column instead of semi column...that could be your error.

Vincent

Ask a Question
Discussion stats
  • 4 replies
  • 222 views
  • 6 likes
  • 3 in conversation