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

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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