BookmarkSubscribeRSS Feed
mcook
Quartz | Level 8

I am trying to recreate a table with the following layout

 

mcook_0-1634144792679.png

The input dataset is simply the 3 columns,  Grouping, Var1, and N1

mcook_1-1634145295070.png

etc.

 

How do i create the Total for each Group?  

 

3 REPLIES 3
mcook
Quartz | Level 8

Apologies, i forgot to specify.  I am trying to accomplish this in ODS Tagsets.RTF Proc Report.

PaigeMiller
Diamond | Level 26

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;

 

--
Paige Miller
Ksharp
Super User

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;

20211014200139.png

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 933 views
  • 1 like
  • 3 in conversation