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
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.
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;
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.