Coding exercise answers


**** Question 1 ****;

data groups;
set input48;
if upcase(cvar) in ('A', 'B', 'C', 'D', 'E', 'F', 'G') then group=1;
else if upcase(cvar) in ('H', 'I', 'J', 'K', 'L', 'M', 'N') then group=2;
else group=3;
new_y = input(y, 7.3); *convert to numeric;

/* Calculate the average of X and Y by Group */
/* What is the average of X and Y for Group 2? */

proc means data=groups mean maxdec=2;
class group;
var x new_y;
where group=2;

What is the average of X for Group=2? 
Answer: 47 (or 48)

What is the average of Y for Group=2?
Answer 703

**** Question 2 ****;
data class (keep=name sex height group);
set sashelp.class;
length group $ 30;
if sex = "M" and height > 64 then Group="Above Average";
else if sex = "F" and height > 60 then Group="Above Average";
else Group="Below Average";

proc freq data=class;
table group;

There are 10 students whose height is above average and 9 students whose height is below average.