The SAS Output Delivery System and reporting techniques

Insert a row above a section in a report table

Reply
Frequent Contributor
Posts: 102

Insert a row above a section in a report table

Looking for a way to insert a row above each section of a table.  For example, a table can have Races and Age groups like this:

Variable  Value

White      50 

Black      60

Asian      10

Other      20

<20        15

20-30      7

30-50      8

50-75     25

>75       60

In the report, I'd like to display this:

Variable  Value

    R A C E

White      50 

Black      60

Asian      10

Other      20

  A G E   G R O U P

<20        15

20-30      7

30-50      8

50-75     25

>75       60

Appreciate any suggestions.

Haris    

Super User
Posts: 11,121

Re: Insert a row above a section in a report table

How are you generating the tables currently? Code example?

Frequent Contributor
Posts: 102

Re: Insert a row above a section in a report table

Tables are all generated outside of PROC REPORT using SQL, FREQ, MEANS, etc.  It's for the demographics table of a manuscripts with predictors as rows, groups as columns, Ns, p-values, etc.  At the moment, I am only interested in making the output prettier and removing the manual step of adding the section headings.  I don't think what I am looking for can be made entirely in PROC REPORT or any one procedure for that matter.

Thanks,

Haris

Super User
Posts: 11,121

Re: Insert a row above a section in a report table

Proc Tabulate actually does similar to what you want.

Take a look at the output from:

proc tabulate data=sashelp.class;

   class sex;

   class age;

   table sex age,

         n=''*f=f4.0;

run;

But without some details of what your data looks like and what you have tried, we can't get much further.

Summarized data can be displayed using FILE Print and Put statements in a data step if you need something other than "simple" tables, but again we need to know what the data looks like.

Super Contributor
Posts: 307

Re: Insert a row above a section in a report table

Without more specifics it's hard to say what approach to follow. Adding a "space" between the header/column names and the rest of the table is doable -- all depends on the approach(es) you are using.

Frequent Contributor
Posts: 102

Re: Insert a row above a section in a report table

And thought I was as clear as it gets Smiley Happy

Here's the code for full table as well as a PROC REPORT I am currently using--it's a standard table 1 from any medical journal:

data have;

  input Variable $;

  N1 = ranuni(0); N2 = ranuni(0);

  Group1 = put(ranuni(0),8.2); Group2 = put(ranuni(0),8.2);

  PVal= ranuni(0);

  cards;

Var1

Var2

Var3

Var4

AgeGr1

AgeGr2

AgeGr3

Race1

Race2

Race3

Region1

Region2

Region3

Region4

;

run;

proc report data=have;

  column ('Predictor' Variable)

  ('Number of Patients' N1 N2)

  ('Mean/STD' Group1 Group2)

  ('p-value' PVal);

  define Variable / display '';

  define N1 / display center;

  define N2 / display center;

  define Group1 / display center;

  define Group2 / display center;

  define Pval / display center '';

run;

Output is the table below (for some reason the (headers are cut off but they don't matter).  At the moment I am typing the bold category headings manually and would like to automate it.  Tried COMPUTE BEFORE but got lost.

        

Other Pt Variables
A0.99456480.4985552  0.32  0.120.6276928
B0.08050720.6616233  0.05  0.230.4454616
C0.95245910.6282662  0.03  0.38 0.304287
D0.57376790.1142044  0.57  0.490.7099973
Age Group
AgeGr10.95182480.2908635  0.35  0.890.6725817
AgeGr2 0.5073290.5758729  0.84  0.090.6611321
AgeGr30.51575270.4067989  0.98  0.400.4416961
Race
Race10.10755040.9987347  0.96  0.250.5914531
Race20.96695180.6722821  0.88  0.480.4796646
Race30.81725020.8970209  0.42  0.070.6066189
Geographical Region
Region10.61317520.7856588  0.40  0.520.0752222
Region20.98143830.9802798  0.48  0.520.6117008
Region3 0.1767670.2434878  0.82  0.660.6990772
Region40.87582620.9445898  0.72  0.540.8402694
SAS Super FREQ
Posts: 8,819

Re: Insert a row above a section in a report table

Hi,

This paper has several examples of this type of demographic report.

http://www2.sas.com/proceedings/forum2008/173-2008.pdf

In addition if you search PharmaSUG papers at lexjansen.com, you should find more examples.

cynthia

SAS Super FREQ
Posts: 703

Re: Insert a row above a section in a report table

Hi

You can use the COMPUTE BEFORE with a LINE statement to do something like this, see sample code below. For the grouping you need a new variable which is not shown in the report but needed to have "break lines".

Proc Format;
 
value $category
   
"VAR" = "Other PT Variables"
   
"AGEGR" = "Age Group"
   
"RACE" = "Race"
   
"REGION" = "Geographical Region"
  ;
run;
data have;
  input Variable $;
  category = put(upcase(compress(variable, "0123456789")), $category.);
  N1 = ranuni(0);
  N2 = ranuni(0);
  Group1 = put(ranuni(0),8.2);
  Group2 = put(ranuni(0),8.2);
  PVal= ranuni(0);
  cards;
Var1
Var2
Var3
Var4
AgeGr1
AgeGr2
AgeGr3
Race1
Race2
Race3
Region1
Region2
Region3
Region4
;
run;

proc report data=have;
  column category ('Predictor' Variable)

    (
'Number of Patients' N1 N2)

    (
'Mean/STD' Group1 Group2)

    (
'p-value' PVal)
;
  define category / group order=data noprint;
 
define Variable / display '';
 
define N1 / display center;
 
define N2 / display center;
 
define Group1 / display center;
 
define Group2 / display center;
 
define Pval / display center '';

 
compute before category / style={just=left background=bibg};
    l = length(category);
   
line category $varying254. l;
  endcomp;
run;
Ask a Question
Discussion stats
  • 7 replies
  • 476 views
  • 6 likes
  • 5 in conversation