wes patton
wes patton

Reputation: 21

Suppress Subtotal in Proc report

I have a proc report that groups and does subtotals. If I only have one observation in the group, the subtotal is useless. I'd like to either not do the subtotal for that line or not do the observation there. I don't want to go with a line statement, due to inconsistent formatting\style.

Here's some sample data. In the report the Tiki (my cat) line should only have one line, either the obs from the data or the subtotal...

data tiki1;
name='Tiki';
sex='C';
age=10;
height=6;
weight=9.5;
run;

data test;
set sashelp.class tiki1;
run;

Upvotes: 1

Views: 218

Answers (1)

SRSwift
SRSwift

Reputation: 1710

It looks like you are trying do something that proc report cannot achieve in one pass. If however you just want the output you describe here is an approach that does not use proc report.

proc sort data = test;
    by sex;
run;
data want;
    length sex $10.;
    set test end = eof;
    by sex;

    _tot + weight;
    if first.sex then _stot = 0;
    _stot + weight;
    output;

    if last.sex and not first.sex then do;
        Name = "";
        sex = "Subtotal " || trim(sex);
        weight = _stot;
        output;
    end;
    keep sex name weight;
    if eof then do;
        Name = "";
        sex = "Total";
        weight = _tot;
        output;
    end;
run;
proc print data = want noobs;
run;

This method manually creates subtotals and a total in the dataset by taking rolling sums. If you wanted do fancy formatting you could pass this data through proc report rather than proc print, Joe gives an example here.

Upvotes: 1

Related Questions