In reply to Leonid Batkhan. Hi Leonid, thank you a lot for your response. Below I attached the modified code based on your example. I hope it does not take too much space and I hope it is OK. Waiting for your reaction. I also wonder how could I save results of 6 different approaches (below) and apply my optimisation criteria I mentioned in my previous post. How to compare six different datasets as far as sum of counts is concerned and number of non-suppressed cells?

options mprint mlogic symbolgen;
data people_roster;
length ageg $1;
input ageg $ race $ sex $ count;
datalines;
1 A M 6
1 A F 8
1 B M 7
1 B F 10
1 H M 5
1 H F 4
1 M M 1
1 M F 2
1 W M 9
1 W F 9
2 A M 7
2 A F 0
2 B M 2
2 B F 6
2 H M 1
2 H F 3
2 M M 2
2 M F 2
2 W M 5
2 W F 8
3 A M 1
3 M M 5
3 M F 2
3 B M 3
3 B F 3
3 H M 8
3 H F 16
3 W M 9
3 W F 10
4 A M 6
4 A F 0
4 B M 7
4 B F 9
4 H M 8
4 M F 1
4 M M 1
4 H F 11
4 W M 10
4 W F 10
;

%let sup_max = 2; /* suppression constraint based on value */
%let sup_avg = 1; /* suppression constraint based on average */

%let tclass1 = race;
%let tclass2 = ageg;
%let tclass3 = sex;
%let tlabel1 = Race;
%let tlabel2 = Age Group;
%let tlabel3 = Sex;
%let f1 = $racef;
%let f2 = $agegf;
%let f3 = $sexgf;

%let hbcolor = edf2f9; /* header background color */
%let hfcolor = 3872ac; /* header font color */

proc format;
value $racef (notsorted)
'M' = 'Martian'
'A' = 'Asian'
'B' = 'Black'
'H' = 'Hispanic'
'W' = 'White'
' ' = 'Total'
;
value $agegf (notsorted)
'1' = '<18'
'2' = '19-64'
'3' = '65-99'
'4' = '100+'
' ' = 'Total'
;
value $sexgf (notsorted)
'M' = 'Male'
'F' = 'Female'
' ' = 'Total'
;
value cntf
.S = '*'
. = '0'
other = [comma18.0]
;
value $totbgf
'Total' = "&hbcolor"
;

run;

/* generate table output */
options nocenter pagesize=max;
title1 color=cx&hfcolor 'People by Race, Sex and Age Group';
ods html style=styles.seaside path='D:\' file='report2.html';

%macro printreport(dsname=);

/* generate footnote */
%let ftnote=;
data _null_;
set &dsname (where=(count eq .S));
call symput('ftnote',"j=L h=10pt '*) The data is suppressed to protect privacy'");
stop;
run;
footnote &ftnote;

proc report data=&dsname nowd split='*' spanrows missing
style(header)=[font_size=11pt just=C color=#&hfcolor]
style(column)=[font_size=10pt just=L];
column &tclass1 &tclass3 count,&tclass2 count=tot;
define &tclass1 / group order=data "&tlabel1" f=&f1.. preloadfmt style(column)=header[vjust=m cellwidth=1.5in color=#&hfcolor];
define &tclass3 / group order=data "&tlabel3" f=&f3.. preloadfmt style(column)=header[vjust=m cellwidth=1.5in color=#&hfcolor];
define &tclass2 / across order=data "&tlabel2" f=&f2.. preloadfmt style(header)=[background=$totbgf.];;
define count / display 'People Reported' style(column)=[just=R cellwidth=1in] f=cntf.;
define tot / sum noprint;

compute &tclass3;
if &tclass3 eq ' ' then
do;
call define(_col_,'style',"style=[just=C font_size=11pt color=#&hfcolor]");
call define(_row_,'style',"style=[font_weight=bold background=#&hbcolor]");
end;
endcomp;

compute &tclass2;
call define("_c&totcol._",'style',"style=[font_weight=bold just=R background=#&hbcolor]");
endcomp;
run;

%mend printreport;

proc means data=people_roster noprint completetypes;
format &tclass1 &f1.. &tclass2 &f2.. &tclass3 &f3..;
class &tclass1 &tclass2 &tclass3/ preloadfmt order=data;
var count;
output out=people_sup1 sum(count)=count sum(count)=cnt_orig;
run;

/* get number of columns for table report */
data _null_;
set people_sup1 (where=(_type_ eq 2)) end=e;
totcol + 1;
if e then call symputx('totcol',totcol + 3); *<-- Column number for Total;
run;
%put ***&totcol***;

%printreport(dsname=people_sup1);

/* suppression macro definition */
%macro suppress(in,supclass1,supclass2,out);

proc sort data=&in out=&in._sorted(keep=&tclass1--cnt_orig);
by &supclass1 &supclass2 count;
run;

%let sup_flag = 0;

data &out;
set &in._sorted;
by &supclass1 &supclass2 count;

if first.&supclass1 or first.&supclass2 then
do; /* initialize number and sum of suppressed cells */
_supn_ = 0;
_supsum_ = 0;
end;

/* enhanced suppression flag */
if (_supn_ ne 0) then avg_flg = (_supsum_/_supn_ <= &sup_avg);

/* apply suppression criteria */
if (count>0) and ( count<=&sup_max or _supn_=1 or avg_flg ) then
do; /* suppress cell */
count = .S;
call symputx('sup_flag',1);
end;

if (count eq .S) then
do; /* increment number and sum of suppressed cells */
_supn_ + 1;
_supsum_ + cnt_orig;
end;
run;

%mend suppress;

/* suppression iteration macro definition */
%macro iterate_suppression (class1=, class2=, class3=);

%let nextclass1 = &class1;
%let nextclass2 = &class2;

%let i = 1;
%do %while (&sup_flag); /* iterate suppression across dimension */

%let j = %eval(&i + 1);
%suppress(in=people_sup&i, supclass1=&nextclass1, supclass2=&nextclass2, out=people_sup&j);
%let i = &j;

/* swap dimension */
%if (&nextclass1 eq &class1) and (&nextclass2 eq &class2) %then
%do;
%let nextclass1 = &class2;
%let nextclass2 = &class3;
%end;
%else %if (&nextclass1 eq &class2) and (&nextclass2 eq &class3) %then
%do;
%let nextclass1 = &class3;
%let nextclass2 = &class1;
%end;
%else %do;
%let nextclass1 = &class1;
%let nextclass2 = &class2;
%end;

%printreport(dsname=people_sup&j);
%end;

%let order = &class1, &class2, &class3;
%mend iterate_suppression;

%let sup_flag = 1;
%iterate_suppression (class1=&tclass2, class2=&tclass3, class3=&tclass1);

proc sql noprint;
select count(*) into: suppcells
from &syslast
where count = .S;
select sum(cnt_orig) into: suppcounts
from &syslast
where count = .S and (&tclass1^="Total" or &tclass2^="Total" or &tclass3^="Total");
quit;

ods TEXT="Order of variables: &order";
ods TEXT="Number of suppressed cells: &suppcells";
ods TEXT="Frequencies in suppressed cells: &suppcounts";
ods html close;

/*
proc datasets lib=work kill nolist;
quit;
*/