Easynow
Easynow

Reputation: 201

SAS Proc Report banded rows with skipped line

I am using PROC REPORT to generate an output. I need banded lines of alternate colours and am able to achieve this by incrementing a counter variable and testing to see if the row number is odd or even, this works as expected. I am also using a compute block to add a blank line after each group of order variables. I would like the background colour of the blank line to also be determined by the value of the counter variable, but this doesn't seem to be possible. I do not want to go down the route of adding the blank line to the dataset before running PROC REPORT, is there a solution. Please find code below:

PROC REPORT DATA = sashelp.class NOWD SPLIT = "!" HEADLINE HEADSKIP MISSING ;
  COLUMN sex name ;
  DEFINE sex / ORDER ;
  ***this adds banding to the rows and works as expected ***;
  COMPUTE name;
    count+1;
    IF MOD(count, 2) gt 0 THEN DO;
      CALL DEFINE(_ROW_,'STYLE','style=[background=red]');
    END;
    ELSE DO;
      CALL DEFINE(_ROW_,'STYLE','style=[background=green]');
    END;
  ENDCOMP;
  ***section adds a blank line and I can control the background colour but I can t assign this colour based on the value of the count variable ***; 
  COMPUTE AFTER sex  /  style=[background=blue] ; 
    LINE " "    ;
  ENDCOMP;
RUN;

Upvotes: 0

Views: 1058

Answers (1)

whymath
whymath

Reputation: 1394

There is always the old way:

proc sort data = sashelp.class out = test;
  by sex;
run;

data test;
  set test;
  by sex;

  output;
  if last.sex then do;
    call missing(name);
    output;
  end;
run;

proc report data = test;
  column sex name ord;
  define sex /order order = data;
  define ord /noprint;

  compute name;
    count + 1;
    if mod(count, 2) then do;
      call define(_row_,'style','style=[background=green]');
    end;
    else do;
      call define(_row_,'style','style=[background=red]');
    end;
  endcomp;
run;

If you can solve it just by modifying an option, please share your skill.

Upvotes: 0

Related Questions