options ps=66 ls=70 pageno=1 nodate nonumber;
data fundrais;
   input @1 team $ @6 grade @8 classrm $ @10 name $
      @19 pencils @23 tablets; totsale=pencils+tablets;

   /* Determine percents and proportions for row containing    */
   /*    value of interest.                                    */
if classrm='A' then do;
   capct=100;
   cappn=1;
   casum=1;
end;
else do;
   capct=0;
   cappn=0;
   casum=0;
end;

   /* Determine percents and proportions for column containing */
   /*    value of interest.                                    */
if grade=4 then do;
   g4pct=100;
   g4ppn=1;
   g4sum=1;
end;
else do;
   g4pct=0;
   g4ppn=0;
   g4sum=0;
end;

cards;
BLUE 4 A ANN      4   8
RED  4 A MARY     5   10
BLUE 4 A JOHN     6   4
RED  4 A BOB      2   3
BLUE 4 B FRED     6   8
RED  4 B LOUISE   12  2
BLUE 4 B ANNETTE  .   9
RED  4 B HENRY    8   10
BLUE 4 C KATHY    4   7
BLUE 4 C JIM      3   9
RED  4 C STEVE    13  7
BLUE 5 A ANDREW   3   5
RED  5 A SAMUEL   12  10
BLUE 5 A LINDA    7   12
RED  5 A SARA     4   .
BLUE 5 B MARTIN   9   13
RED  5 B MATHEW   7   6
BLUE 5 B BETH     15  10
RED  5 B LAURA    4   3
;
run;

proc tabulate format=10.;
   class grade;
   var cappn;
   table grade,cappn*(n mean*f=10.2 sum)/rts=14;
   keylabel n='Total' mean='Proportion' sum='N';
   label cappn='Classroom A' grade='Grade';
   title 'Proportion of Students in Classroom A for each Grade (Single Column)';
   title2 'See SAS Guide to TABULATE Processing, Page 50, Figure 3.19';
run;

proc tabulate format=6.;
   class classrm;
   var g4ppn;
   table g4ppn*(n mean*f=6.2 sum),classrm/rts=25;
   keylabel n='Total' mean='Proportion' SUM='N';
   label g4ppn='Grade 4' classrm='Classroom';
   title 'Proportion of Students in Grade 4 for each Classroom (Single Row)';
   title2 'See SAS Guide to TABULATE Processing, Page 56, Figure 3.25';
run;

proc tabulate format=10.;
   class grade;
   var capct;
   table grade,capct*(n mean)/rts=14;
   keylabel n='Total' mean='Percent';
   label capct='Classroom A' grade='Grade';
   title 'Percent of Students in Classroom A for each Grade';
   title2 'See SAS Guide to TABULATE Processing, Page 50, Figure 3.19';
run;

proc tabulate format=6.;
   class classrm;
   var g4pct;
   table g4pct*(n mean),classrm/rts=20;
   keylabel n='Total' MEAN='Percent';
   label g4pct='Grade 4' classrm='Classroom';
   title 'Percent of Students in Grade 4 for each Classroom';
   title2 'See SAS Guide to TABULATE Processing, Page 56, Figure 3.25';
run;

proc tabulate format=10.;
   class grade;
   var capct casum;
   table grade,casum=' '*sum
      capct=' '*mean/rts=14 box='Classroom A';
   keylabel sum='N' mean='Percent';
   label casum='Classroom A' capct='' grade='Grade';
   title 'Percent of Students in Classroom A for each Grade';
   title2 'See SAS Guide to TABULATE Processing, Page 50, Figure 3.19';
run;

proc tabulate format=6.;
   class classrm;
   var g4pct g4sum;
   table g4sum=''*sum g4pct=''*mean,classrm/rts=15
      box='Grade 4' row=float;
   keylabel sum='N' mean='Percent';
   label g4pct='Grade 4' classrm='Classroom';
   title 'Percent of Students in Grade 4 for each Classroom';
   title2 'See SAS Guide to TABULATE Processing, Page 56, Figure 3.25';
run;