BookmarkSubscribeRSS Feed
odmhx
Calcite | Level 5
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!
4 REPLIES 4
ChrisNZ
Tourmaline | Level 20
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;
odmhx
Calcite | Level 5
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
data_null__
Jade | Level 19
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]
odmhx
Calcite | Level 5
Thank you so much! It really solves my problem!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1552 views
  • 0 likes
  • 3 in conversation