I would like to add a total row to my table. Here is what I have:
Gender | Freq | Percent |
Males | 20 | 25% |
Females | 60 | 75% |
Here is what I'd like:
Gender | Freq | Percent |
Males | 20 | 25% |
Females | 60 | 75% |
Total | 80 |
Just want the total there as its own row. What's the best proc to do this, as I realize you can do this a number of ways (tabulate, sql, etc.)
Thanks!
data have;
input Gender $ Freq Percent :percent.;
format percent percent.;
cards;
Males 20 25%
Females 60 75%
;
proc sql;
select * from have
union all
select 'Total', sum(freq),. from have;
quit;
/*or*/
proc report data=have;
column gender freq percent;
define freq/analysis;
compute after;
line 'Total' +2 freq.sum ;
endcomp;
run;
data have;
input Gender $ Freq Percent :percent.;
format percent percent.;
cards;
Males 20 25%
Females 60 75%
;
proc sql;
select * from have
union all
select 'Total', sum(freq),. from have;
quit;
/*or*/
proc report data=have;
column gender freq percent;
define freq/analysis;
compute after;
line 'Total' +2 freq.sum ;
endcomp;
run;
Hi:
Or, in the interest of completeness -- without a LINE statement and using an RBREAK statement, you can generate the report either with or without a total for percent:
Cynthia
Yes thought of it. Just seemed straight forward enough to use the computed memory value by the engine soon as a variable was defined analysis. Point taken. Thank you 🙂
Yes that makes sense. I agree! 🙂 Thank you!
Also , @Cynthia_sas If you happen to know Jane Eslinger, please pass on my regards and gratitude to her for having authored that lovely proc report book. Kudos!!! I would say, a must read.
data have;
set sashelp.class;
run;
proc sql;
select sex,count(*) as n,calculated n/(select count(*) from have) as percent format=percent8.2
from have
group by sex
union all
select 'Total' ,(select count(*) from have),. from have(obs=1);
quit;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.