Exercise (1-2)


Copy and run the code from the yellow box below:

The INPUT48 data set contains three columns.

Copy and paste the code below into your SAS editor:

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;

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

proc means data=groups average maxdec=2;
class group;
var x y;
if group=2;

The program is intended to:

  • Create 3 groups for Cvar: A-G is Group=1; H-N is Group=2; O-Z is Group=3.
  • All variations of the variable should be in the same group, i.e. "A" and "a" should be in Group=1.
  • Calculate the average of X and Y by Group.

There are multiple errors in the program. These may be syntax errors, logic errors, or problems with the program structure. Logic errors might not produce messages in the log, but will cause the program to produce results different than intended.

Correct the errors, run the program, and then use the results to answer the next 2 questions.

  • What is the average of X for Group=2? 
  • What is the average of Y for Group=2?