/* STAT 541 HW 7 Example Solutions */ /* Problem 1(a) */ data baseball; set sashelp.baseball; if position='1B' or position='2B' or position='3B' or position='SS' then PlayerType='Infielder'; else if position='LF' or position='CF' or position='RF' or position='OF' then PlayerType='Outfielder'; else PlayerType='Other'; run; PROC PRINT data=baseball; VAR Name PlayerType; run; /* Problem 1(b) */ data baseball2; LENGTH PlayerType $ 10; set sashelp.baseball; if position='1B' or position='2B' or position='3B' or position='SS' then PlayerType='Infielder'; else if position='LF' or position='CF' or position='RF' or position='OF' then PlayerType='Outfielder'; else PlayerType='Other'; run; PROC PRINT data=baseball2; VAR Name PlayerType; run; /* Problem 2(a) */ data baseball; set sashelp.baseball; BatAvg = nhits/natbat; run; PROC MEANS data=baseball MEAN; VAR BatAvg; run; /* Problem 2(b) */ data baseball; LENGTH BatAvg 3.; set sashelp.baseball; BatAvg = nhits/natbat; run; PROC MEANS data=baseball MEAN; VAR BatAvg; run;