Use SASHELP.BASEBALL
Write a code to identify count of players in League by Division. Save the counts in a macro
variable to display as below in red.
Also derive the n(%) for every team
N=total number of players in National East etc.
n(%)= n is no. of players in team e.g St. Louis in National East) while
% is (n/N * 100)
Write a proc report to create below output as rtf file
Please change the title to something meaningful, e.g. "Homework - Need help in writing a macro". Then post the code you have already tried.
proc sort data=sashelp.baseball out=baseball;
by league division;
run;
proc freq data=baseball;
tables team/nocum out=base;
by league division;
run;
proc sql;
create table d as select league, division, sum(Count) as totalplayers from base
group by league, division;
quit;
proc sql noprint;
select totalplayers into :n1 - :n4 from d
order by league, division;
quit;
%put &n1 &n2 &n3 &n4;
data base1;
merge base d;
by league division;
count_percent=strip(put(count,best.))||"("||strip(round(percent,0.01))||")";
abbre=substr(league,1,1)||substr(division,1,1);
run;
proc sort data=base1;
by team;
run;
proc transpose data=base1 out=base2;
by team;
var count_percent;
id abbre;
run;
data base3;
set base2;
if missing(NE) then NE="0(0.00)";
if missing(NW) then NW="0(0.00)";
if missing(AE) then AE="0(0.00)";
if missing(AW) then AW="0(0.00)";
run;
proc report data=base3 headskip headline nowd center split='*';
column Team gap ("National" NE NW ) ("American" AE AW );
define Team/ "Teams" ;
define gap / ' ' style={cellwidth=0.75in};
define NE/ "East*(N=&n3)";
define NW/ "West*(N=&n4)";
define AE/ "East*(N=&n1)" ;
define AW/ "West*(N=&n2)" ;
run;
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!
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.