For creating custom format tables, which includes inconsistent values per column, data is usually manipulated in data step.
In this specific case I would do the following steps (there might be more efficient ways to do it):
*step 1;
proc means data=sashelp.class nway;
ways 1;
class sex;
var height weight;
output out=means1;
run;
proc means data=sashelp.class;
var height weight;
output out=means2;
run;
*step 2;
proc transpose data=means1 out=wide1;
by sex;
var height weight;
id _stat_;
proc print;run;
proc transpose data=means2 out=wide2;
by _type_;
var height weight;
id _stat_;
proc print;run;
*step 3;
data wide1a;
set wide1;
length M_STD MIN_MAX $15;
M_STD= strip(put(mean, 6.2))||' ('||strip(put(std, 6.2))||')';
MIN_MAX= strip(put(min, best.))||' - '||strip(put(max, best.));
proc print; run;
proc sort data= wide1a; by _name_; run;
proc transpose data=wide1a out=narrow1;
by _name_ ;
var m_std min_max;
id sex;
proc print; run;
data wide2a;
set wide2;
length M_STD MIN_MAX $15;
M_STD= strip(put(mean, 6.2))||' ('||strip(put(std, 6.2))||')';
MIN_MAX= strip(put(min, best.))||' - '||strip(put(max, best.));
proc print; run;
proc transpose data=wide2a out=narrow2 (rename=(col1=TOTAL));
by _name_ ;
var m_std min_max;
proc print; run;
*step 4;
data final;
merge narrow1 narrow2;
by _name_;
if find(f, '(') gt 0 then stat= 'mean (std)';
else do;
stat= 'min - max';
_name_='';
end;
proc print; run;
proc report data= final split='~';
column _name_ stat('Sex' f m) ('Both~' total);
define _name_/'' display;
define stat/'' display;
define f/ 'F' display;
define m/'M' display;
define total/'' display;
run;
result;
... View more