BookmarkSubscribeRSS Feed
magicdj
Obsidian | Level 7

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

table.jpg

 

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;
3 REPLIES 3
Reeza
Super User
For the desired format, the fastest solution is to create the data into a data set and then use PROC PRINT/REPORT to display. Use the CATT or CATX to create the variables with STD in brackets and such.
magicdj
Obsidian | Level 7

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

 

 table2.jpg

ballardw
Super User

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.

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 811 views
  • 2 likes
  • 3 in conversation