Help using Base SAS procedures

How to conditionally break and summarize

Reply
Contributor
Posts: 35

How to conditionally break and summarize

In proc report, I need to display each year's spending for 4 years, but only summarize 3 years at year break level. How do I do that?

Your help is appreciated!
PROC Star
Posts: 1,630

Re: How to conditionally break and summarize

You can use this example to get you started:
[pre]
proc report data=sashelp.class;
column SEX AGE WEIGHT ;
define SEX / group;
define AGE / group;
define WEIGHT / analysis sum;
compute after AGE ;
if AGE>13 then TOTAL + WEIGHT.sum;
endcomp;
compute before SEX;
TOTAL=.;
endcomp;
compute after SEX;
line @ 20 ' Sum for ' SEX $1. ' age > 13: ' TOTAL 4.;
endcomp;
run;
Contributor
Posts: 35

Re: How to conditionally break and summarize

Thank you for your code. However, what I was trying to do was not to calculate the sum of female, but only to calculate the sum of the male.. So the output would look like this:

Listing of NUMBERS Data Set

S
e
x Age Weight
F 11 50.5
12 161.5
13 182
14 192.5
15 224.5

M 11 85
12 310.5
13 84
14 215
15 245
16 150
Sum for M age > 13: 610
Respected Advisor
Posts: 3,780

Re: How to conditionally break and summarize

This this small modification to the (LINE) section of the code supplied by Chris.

[pre]
options ls=64;
proc report data=sashelp.class nowd list;
column SEX AGE WEIGHT ;
define SEX / group;
define AGE / group;
define WEIGHT / analysis sum;
compute after AGE ;
if AGE>13 then TOTAL + WEIGHT.sum;
endcomp;
compute before SEX;
TOTAL=.;
endcomp;
compute after SEX;
line = catx(' ','Sum for', sex,'age > 13:',total);
l = length(line);
if sex eq 'F' then l=0;
line @20 line $varying50. l;
*line @ 20 ' Sum for ' SEX $1. ' age > 13: ' TOTAL 4.;
endcomp;
run;
[/pre]
Contributor
Posts: 35

Re: How to conditionally break and summarize

Thank you so much! It really solves my problem!
Ask a Question
Discussion stats
  • 4 replies
  • 99 views
  • 0 likes
  • 3 in conversation