- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
PROC PRINT will also do that...
The best proc depends on what you're doing next and why you're doing this in the first place.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Cynthia
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Cynthia
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;