BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10

DATA CLASS;

LENGTH SEX $20.;

SET sashelp.class;

IF AGE IN (12, 14);

RUN;

 

 

proc report =class nowd;

column age sex n height weight ;

define age / group;

define sex / group;

define height / sum;

define weight / sum;

compute after;

 

sex='TOTAL';

endcomp;

rbreak after /summarize;

RUN;

 

How would I insert an average (bottom-line) or vertically for one or both of the variables (height, weight) based on the bottomline total

3 REPLIES 3
PaigeMiller
Diamond | Level 26

I'm going out on a limb here and say that I don't think you can do this directly in PROC REPORT, but furthermore it doesn't make sense to have cells with sums and at the bottom of the table, cells with average. The average would not be meaningful and would be confusing to anyone looking at the sums in the majority of the table.

 

If you want to display averages in the table and then averages on the bottom line, then this should be simple to do in PROC REPORT.

 

--
Paige Miller
Ksharp
Super User

Do you like SQL ?

 

DATA CLASS;
LENGTH SEX $20.;
SET sashelp.class;
IF AGE IN (12, 14);
RUN;

proc format ;
value fmt
 9999=' ';
run;
options missing=' ';
proc sql;
select age format=fmt8.,sex,count(*) as n,sum(height) as height,sum(weight) as weight
 from class
  group by age,sex
union 
select 9999 ,'total',count(*),sum(height),sum(weight) from class
union
select 9999 ,'average',.,avg(height),avg(weight) from class;
quit;

Ksharp
Super User

proc report data=class nowd;
column age sex n height weight height=h weight=w;
define age / group;
define sex / group;
define height / sum;
define weight / sum;
define h/mean noprint;
define w/mean noprint;
compute after;
sex='TOTAL';
line @10 'Average' @30 h 8.2 @40 w 8.2;
endcomp;

rbreak after /summarize;

RUN;

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

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 945 views
  • 0 likes
  • 3 in conversation