You can try this code but use your data.
proc format;
value agefmt
18 - 40= '18 - 40'
41 - 64 = '41 - 64'
65 - HIGH = '>= 65'
;
value trtf
1='Active'
2='Placebo'
;
run;
proc sql noprint;
select count(distinct usubjid) into: n1
from echo.dm
where armcd='ECHOMAX';
select count(distinct usubjid) into: n2
from echo.dm
where armcd='PLACEBO';
quit;
%put &=n1 &=n2;
proc means data = dm completetypes n noprint nway;
format age agefmt. trt01an trtf.;
class trt01an age / preloadfmt;
var age;
output out=agestats n=_n;
run;
proc sort data=agestats;
by age;
run;
proc transpose data = agestats out=agestats_t prefix=col;
by age;
var _n;
run;
proc means data = dm completetypes n noprint nway;
format trt01an trtf.;
class trt01an / preloadfmt;
var trt01an;
output out=trtcounts n=_n;
run;
proc sort data=trtcounts;
by trt01an;
run;
proc transpose data = trtcounts out=trtcounts_t prefix=col;
var _n;
run;
data stack;
length cat0 $200;
set trtcounts_t(in=a) agestats_t(in=b);
if a then cat0='n';
else cat0 = put(age,agefmt.);
array trtcounts[2] (&n1 &n2);
array cnts[2] col1 col2;
array pcts[2] pct1 pct2;
array values[2] $14 value1-value2;
if b then do;
do i=1 to dim(cnts);
if missing(cnts[i])=0 then pcts[i] = 100*cnts[i]/trtcounts[i];
values[i]=strip(put(cnts[i],8.))||'('||strip(put(pcts[i],5.1))||')';
end;
end;
if a then do;
do i= 1 to dim(cnts);
values[i] = strip(put(cnts[i],8.));
end;
end;
drop i;
run;
... View more