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):
There are two things I want to accomplish:
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;
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.