Sas how to have 2 byvar in a display

520 Views Asked by At

Normally in sas proc report we can use the byvar/byval to have the by category at the top of the display. In my case my display has 2 by categories. And I am not sure how to do that. I can add one using proc report but I don't know how to add 2.

I want my display to be like:

Sex: Male (100) Treatment: Aspirin (40mg) (N=21)

column1 column2 column3

1

There are 1 best solutions below

0
On

Precompute the group size and add that variable to the by grouping. Use inline styling in a single TITLE statement, or TITLE1 TITLE2 statements.

Example:

data have;
  call streaminit (2021);
  do g1=1 to 3;
  do g2=1 to 3;
    do _n_ = 1 to rand('integer', 5);
      pid + 1;
      array c col1-col3;
      do over c; z+1; c=z; end;
      output;
    end;
  end;
  end;
  drop z;
run;

options nodate nonumber nocenter nobyline;
ods escapechar='^';

proc sql;
  create table reportdata as
  select *, count(*) as count from have group by g1, g2 order by g1, g2, col1;

proc report data=reportdata;
  title '#byvar1: #byval1^n#byvar2: #byval2 (n=#byval3)';
  by g1 g2 count;
  columns col1-col3;
  define col1-col3/display;
run;

Output:

enter image description here