I am trying to recreate a table with the following layout
The input dataset is simply the 3 columns, Grouping, Var1, and N1
etc.
How do i create the Total for each Group?
Apologies, i forgot to specify. I am trying to accomplish this in ODS Tagsets.RTF Proc Report.
Using data set SASHELP.CLASS, I can produce the requested report
proc sort data=sashelp.class out=class;
by sex;
run;
data class;
set class;
by sex;
if first.sex then index=0;
index+1;
sample=cats('Sample',index);
drop index;
run;
/* Now I have a data set similar to yours */
/* PROC REPORT does the rest */
proc report data=class;
columns sex sample height;
define sex/group;
define sample/display;
define height/sum;
break after sex/summarize;
compute after sex;
sample='Total';
sex=' ';
endcompute;
run;
How about this one ?
ods Tagsets.RTF file='c:\temp\temp.rtf' style=journal;
proc sql;
create table have as
select sex,1 as id,Smoking_Status,sum(weight) as weight
from sashelp.heart
group by sex,Smoking_Status
union
select sex,2 as id,'Total',sum(weight) as weight
from sashelp.heart
group by sex
;
quit;
proc report data=have nowd spanrows missing
style(report)={rules=cols }
style(header)={fontstyle=roman fontweight=bold background=verylightgrey borderbottomcolor=black borderbottomwidth=2px} ;
columns sex id Smoking_Status weight;
define sex/group style={just=c vjust=m bordertopcolor=black bordertopwidth=2px};
define id/group noprint;
define Smoking_Status/group;
define weight/display;
compute Smoking_Status;
if Smoking_Status='Total' then
call define(_row_,'style','style={bordertopcolor=black bordertopwidth=2px borderbottomcolor=black borderbottomwidth=2px}');
endcomp;
run;
ods Tagsets.RTF close;
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 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.