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
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;
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.