## proc report, subtotal when using group/noprint

Solved
Occasional Contributor
Posts: 10

# proc report, subtotal when using group/noprint

Hi

How do I display a text "Subtotal of [sex]" in the age column in this example;

ods listing close ;

ods html;

proc report data=sashelp.class nowd;

column sex age height;

define sex / group  noprint ;

compute before sex / style=[just=l fontweight=bold];

text1=sex;

line text1 \$;

endcomp;

define age / group  ;

compute age;

if _break_='_RBREAK_' then do;

call define("age", 'style', 'style=[pretext="Total "]');

end;

endcomp;

define height / analysis SUM ;

break after sex / summarize ;

rbreak after / summarize;

run;

ods html close; Run ;

Accepted Solutions
Solution
‎05-25-2012 07:38 AM
Super User
Posts: 10,784

## Re: proc report, subtotal when using group/noprint

Ou. You have changed the age from numeric to character.

If you allow this transformation ,that would very easy. I think you can do it better.

```data test;
set sashelp.class;
age_text = put(age,10.);
run;

ods listing close ;
ods html file='c:\x.html';
options missing=' ';
proc report data=test nowd out=x;
column sex age_text height;
define sex / group noprint ;
define age_text / group missing ;
define height / analysis SUM ;
compute before sex ;
age_text = sex;call missing(height.sum);
endcomp;
compute after sex;
age_text = catx(' ',"subtotal",sex);
endcomp;
compute after ;
age_text = "total";
endcomp;
break before sex / summarize ;
break after sex / summarize ;
rbreak after / summarize;
run;
Run ;
ods html close;
ods listing;

```

Ksharp

All Replies
Super User
Posts: 10,784

## Re: proc report, subtotal when using group/noprint

```ods listing close ;
ods html;
proc report data=sashelp.class nowd;
column sex age height;
define sex / group  noprint ;
compute after sex / style=[just=l fontweight=bold];
text1='Subtotal of '||sex;
line text1 \$34. height.sum best10.;
endcomp;
compute after /style=[just=l fontweight=bold];
text2='Total';
line text2 \$40. height.sum best10.;
endcomp;
define age / group  ;
compute age;
if _break_='_RBREAK_' then do;
call define("age", 'style', 'style=[pretext="Total "]');
end;
endcomp;
define height / analysis SUM ;
run;

ods html close;

```

Ksharp

Occasional Contributor
Posts: 10

## Re: proc report, subtotal when using group/noprint

Ksharp, thanks. Didn't seem to work as I wanted though. But found out:

data test;

set sashelp.class;

age_text = put(age,10.);

run;

ods listing close ;

ods html;

proc report data=test nowd;

column sex age_text height;

define sex / group noprint ;

compute before sex / style=[just=l fontweight=bold];

text1=sex;

line text1 \$;

endcomp;

define age_text / group missing ;

define height / analysis SUM ;

break after sex / summarize ;

compute after sex;

age_text = "subtotal";

endcomp;

rbreak after / summarize;

run;

quit;

ods html close; Run ;

Solution
‎05-25-2012 07:38 AM
Super User
Posts: 10,784

## Re: proc report, subtotal when using group/noprint

Ou. You have changed the age from numeric to character.

If you allow this transformation ,that would very easy. I think you can do it better.

```data test;
set sashelp.class;
age_text = put(age,10.);
run;

ods listing close ;
ods html file='c:\x.html';
options missing=' ';
proc report data=test nowd out=x;
column sex age_text height;
define sex / group noprint ;
define age_text / group missing ;
define height / analysis SUM ;
compute before sex ;
age_text = sex;call missing(height.sum);
endcomp;
compute after sex;
age_text = catx(' ',"subtotal",sex);
endcomp;
compute after ;
age_text = "total";
endcomp;
break before sex / summarize ;
break after sex / summarize ;
rbreak after / summarize;
run;
Run ;
ods html close;
ods listing;

```

Ksharp

Occasional Contributor
Posts: 10

## Re: proc report, subtotal when using group/noprint

Thanks ! That also works as intended.

Br.

SAS Super FREQ
Posts: 9,370

## Re: proc report, subtotal when using group/noprint

Hi:

Another alternative is to use your PRETEXT technique for the report break and  as for the other breaks. The only difference is that you need to build your style= override string into a variable for the CALL DEFINE statement.

cynthia

ods listing close ;

ods html file='c:\temp\something.html' style=sasweb;

proc report data=sashelp.class nowd;

column sex age height;

define sex / group  noprint ;

define age / group  style(column)={cellwidth=1in};

define height / analysis SUM ;

break after sex / summarize ;

rbreak after / summarize;

compute before sex / style=[just=l fontweight=bold];

text1=sex;

line text1 \$5.;

endcomp;

compute age;

length pt \$20 sstr \$50 text1 \$1;

if _break_='_RBREAK_' then do;

call define("age", 'style', 'style=[pretext="Total "]');

end;

if upcase(_break_) = 'SEX' then do;

pt= catx(' ', 'Subtotal of',text1);

sstr = 'style=[pretext="'||trim(pt)||'"]';

** use temporary variable for value of style override;

call define("age", 'style', sstr);

end;

endcomp;

run;

ods html close;

🔒 This topic is solved and locked.