BookmarkSubscribeRSS Feed
tburus
Obsidian | Level 7

I am making a somewhat complicated summary table in PROC REPORT where I want to summarize within each group variable and summarize the group variables themselves. Here is a picture of what I have (with flags included):

plot.png

There are two things I want to accomplish:

  1. I want to provide overall summaries for 'Competition' and 'Practice' event types at the top, under the 'Overall Total' summary
  2. I want to suppress the sport names that are being duplicated

Is this possible? I'd love to do it through PROC REPORT without having to just brute force a new dataset to make it work. Below is my current code:

proc report data=all_t1 nowd split="*"
		style(report)=[frame=hsides rules=none]
		style(header)=[background=white color=&rgreen. borderbottomcolor=black]
		style(lines)=[background=white];
	column sport event_type unweightedinj ae ratio weightedinj flag;
	define sport / group '' format=$sport_cap.;
	define event_type / group 'Event Type' center order=formatted style(column)=[cellwidth=1in just=l];
	define unweightedinj / analysis '# Injuries' format=comma8.0 style(column)=[cellwidth=1in just=c];
	define ae / analysis '# Exposures' format=comma8.0 style(column)=[cellwidth=1in just=c];
	define ratio / computed 'Injury Rate *(per 1,000 AEs)' format=8.2 style(column)=[cellwidth=1.75in just=c];
	compute ratio;
		ratio = unweightedinj.sum/ae.sum*1000;
	endcomp;
	define weightedinj / analysis 'Nationally Estimated *# Injuries' format=comma8.0 style(column)=[cellwidth=1.75in just=c];
	define flag / computed format=$25.;  

	break before sport /summarize style(summary)={font_weight=bold};
	rbreak before /summarize style(summary)={font_weight=bold};
	compute sport;
		if _break_ = '_RBREAK_' then sport = 'Overall';
	endcomp;
	compute event_type;
    	if _break_ = 'sport' then event_type = 'Total';
		if _break_ = '_RBREAK_' then event_type = 'Total';
	endcomp;
	compute flag / CHAR;                   
      flag=_BREAK_;                          
   	endcomp;  
run;
1 REPLY 1
MCoopmans
SAS Employee

Hello,

 

I simulated your question with the SASHELP.CARS dataset, and think I found a solution to your second question:

 

ODS _ALL_ close;
ODS listing;

PROC REPORT DATA=SASHELP.CARS LS=93  PS=80  SPLIT="/" CENTER ;
COLUMN  Origin DriveTrain EngineSize Cylinders MPG_Highway;

DEFINE  Origin / GROUP FORMAT= $8. WIDTH=10    SPACING=2   LEFT "Origin" ;
DEFINE  DriveTrain / GROUP FORMAT= $5. WIDTH=10    SPACING=2   LEFT "DriveTrain" ;
DEFINE  EngineSize / SUM FORMAT= BEST9. WIDTH=9     SPACING=2   RIGHT "Engine Size (L)" ;
DEFINE  Cylinders / SUM FORMAT= BEST9. WIDTH=9     SPACING=2   RIGHT "Cylinders" ;
DEFINE  MPG_Highway / SUM FORMAT= BEST9. WIDTH=9     SPACING=2   RIGHT "MPG (Highway)" ;

BREAK BEFORE Origin / SUMMARIZE ;

RBREAK BEFORE  / SUMMARIZE ;

compute drivetrain ;
    	if _break_ = 'Origin' then drivetrain = 'Total';
		if _break_ = '_RBREAK_' then drivetrain = 'Total';
	endcomp;

compute origin;
	if _break_ = '_RBREAK_' then origin = 'Overall';
	else if _break_ ne 'Origin' then origin = " ";
endcomp;
RUN;

ODS _ALL_ close;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 1021 views
  • 0 likes
  • 2 in conversation