BookmarkSubscribeRSS Feed
Riaz97
Calcite | Level 5

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

3 REPLIES 3
andreas_lds
Jade | Level 19

Please change the title to something meaningful, e.g. "Homework - Need help in writing a macro". Then post the code you have already tried.

Riaz97
Calcite | Level 5

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 529 views
  • 1 like
  • 3 in conversation