BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10

proc sql;
create table have as
select Team,
sum(nAtBat) as Tot_Num_Bats,
sum(nHits) as Tot_Num_Hits
from sashelp.baseball
where team in ('Atlanta','Baltimore','
Boston','California','Chicago','Cincinnati','
Cleveland')
group by Team
having sum(nAtBat) >0
order by Team
;quit;

proc report data=have NOWD Wrap style(summary)=Header;
columns Team Tot_Num_Bats Tot_Num_Hits Pct_Num_Bats;

define Tot_Num_Bats / sum "Total # Bats" ;
define Tot_Num_Hits / sum "Total # Hits" ;
define Pct_Num_Bats /computed f=percent8.2 "%Hits" ;
compute Team;
endcomp;
rbreak after / summarize style (summary)= Header;
compute after;
Team = 'Total';
endcomp;
run;

 

I can get the total at the bottom. 

How can I get the percentage of the total to show in the far right column (in this case Pct_Num_Bats). 

I want to do the same for Tot_Num_Hits

1 REPLY 1
blueskyxyz
Lapis Lazuli | Level 10
proc report data=have NOWD Wrap style(summary)=Header;
	columns Team Tot_Num_Bats Tot_Num_Hits Pct_Num_Bats;

	define Tot_Num_Bats / sum "Total # Bats" ;
	define Tot_Num_Hits / sum "Total # Hits" ;
	define Pct_Num_Bats  /computed f=percent8.2 ;

	compute Pct_Num_Bats;
		Pct_Num_Bats= Tot_Num_Hits.sum/Tot_Num_Bats.sum;
	endcomp;
	rbreak after / summarize style (summary)= Header;
	compute after;
		Team = 'Total';
	endcomp;
run;
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
  • 564 views
  • 0 likes
  • 2 in conversation