I try to display N MEAN(SD) se cv q1 median q3 [MIN; MAX] geomean by age group
MEAN(SD) [MIN; MAX] should be display like that in character format.
but, my result is like that:
I have picture format and prefix, but still missing ( or [, also the header Mean and (SD) separate from each other.
I don't know what's the best way to solve the problem.
hope to get some help. thanks a lot
proc sort data=sashelp.class out=class;
by age;
run;
data c1;
set class;
Weightln=log10(Weight);
run;
proc sort data=c1;by age ;
PROC MEANS DATA=c1 NOPRINT;
BY age ;
VAR Weight;
OUTPUT OUT=AB
N=N0
MEAN=Mean0
CV=CV0
STD=SD0
STDERR=SE0
LCLM=LCLM
UCLM=UCLM
MIN=MIN0
Q1=Q10
MEDIAN=Median0
Q3=Q30
MAX=MAX0;
RUN;
proc means data=c1 noprint;
var Weightln;
by age ;
output out=cd mean=logmean var=varlog ;
run;
data gcd;
set cd;
geomean=round(exp(logmean), .001);
run;
proc sql;
create table all as
select a.*,b.geomean
from AB a
left join gcd b
on a.Age=b.age ;
quit;
proc format;
picture mnf (round)
low-high = '009.99';
picture sdf (round)
low-high = ' 009.99)'
.='N/A)'
( prefix = '(' );
picture minf (round)
low-high = '009.99;'
( prefix = '[' );
picture maxf (round)
low-high = '009.99]';
run;
PROC tabulate data=all ORDER=data;
CLASS age;
VAR n0 MEAN0 SD0 se0 cv0 q10 median0 q30 MIN0 MAX0 geomean ;
keyword mean / style=[just=R];
keyword StD / style=[just=L];
TABLE age="" ,
(
n0='n'*max=''*f=4.
mean0='Mean'*max=''*[style=[just=R cellwidth=70 ] f=mnf.]
SD0='(SD)'*max=''*[style=[just=L cellwidth=75 ] f=sdf.]
SE0='SE'*max=''*f=8.2
cv0='CV%'*max=''*f=8.2
Q10='Q1'*max=''*f=8.2
median0='Median'*max=''*f=8.2
Q30='Q3'*max=''*f=8.2
min0='[Min;'*max=''*f=minf.
max0='Max]'*max=''*f=maxf.
geomean='gmean'*max=''*f=8.2
)
/ misstext='---' box=" age" RTS=30 ;
RUN;
thanks, Reeza and ballardw. I believe I need to use proc means and proc report to display. anyone has sample code to create a table like this? thanks a lot
This modifies your std format a bit and uses some different style options. See if it gets close to what you want
proc format library=work;
picture mnf (round)
low-high = '009.99';
picture sdf (round)
low-high = ' 009.99)' ( prefix = '(' )
.= '(N/A)' (noedit)
;
picture minf (round)
low-high = '009.99;'
( prefix = '[' );
picture maxf (round)
low-high = '009.99]';
run;
PROC tabulate data=all ORDER=data;
CLASS age;
VAR n0 se0 cv0 q10 median0 q30 MIN0 MAX0 geomean ;
VAR MEAN0 /style=[just=R borderrightwidth=0];
var SD0 /style=[just=L borderleftwidth=0 ] ;
keyword mean / style=[just=R];
keyword StD / style=[just=L];
TABLE age="" ,
(
n0='n'*max=''*f=4.
mean0='Mean'*max=''*[style=[just=R cellwidth=70 borderrightwidth=0]]*f=mnf.
SD0='(SD)'*max=''*[style=[just=L cellwidth=75 borderleftwidth=0 ]]*f=sdf.
SE0='SE'*max=''*f=8.2
cv0='CV%'*max=''*f=8.2
Q10='Q1'*max=''*f=8.2
median0='Median'*max=''*f=8.2
Q30='Q3'*max=''*f=8.2
min0='[Min;'*max=''*f=minf.
max0='Max]'*max=''*f=maxf.
geomean='gmean'*max=''*f=8.2
)
/ misstext='---' box=" age" RTS=30 ;
RUN;
You may want to look at the CELLPADDING style element if the space between the mean and std seem excessive or too small.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.