1

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;
wes patton
  • 21
  • 3
  • I'm too busy to find the answer right now, but this is an issue that's pretty common and I'm fairly sure has an answer on google, so you might search for "proc report skip subtotal" or something like that. – Joe Mar 26 '15 at 16:01
  • 1
    Actually, it looks like you've asked this same question on communities.sas.com. You should at least link to the question on that site if you're reposting the same question here. (Here: https://communities.sas.com/message/264717) – Joe Mar 26 '15 at 16:07
  • Yup, that's how I ended up here - there's no answer anywhere on google. I'm 90% sure that this isn't possible. – wes patton Mar 26 '15 at 16:48
  • It might be helpful if you could add a little more detail to the question. Specifically; your `proc report code`, and whether you have tried either of Cynthia's two pass suggestions? – SRSwift Mar 26 '15 at 17:59

1 Answers1

1

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.

SRSwift
  • 1,700
  • 9
  • 11