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;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.