Tuesday, June 17, 2014

Computing Geometric Means

This sample is from the SAS Sample Library. For additional information refer to SAS Help and Online Documentation.

 /****************************************************************/
 /*          S A S   S A M P L E   L I B R A R Y                 */
 /*                                                              */
 /*    NAME: GEOMEAN                                             */
 /*   TITLE: Computing Geometric Means                           */
 /* PRODUCT: SAS                                                 */
 /*  SYSTEM: ALL                                                 */
 /*    KEYS: DATASTEP ARRAY MEANS DO FUNCTIONS LOG EXP PRINT     */
 /*   PROCS: MEANS PRINT                                         */
 /*    DATA:                                                     */
 /*                                                              */
 /* SUPPORT:                             UPDATE:                 */
 /*     REF:                                                     */
 /*    MISC:                                                     */
 /*                                                              */
 /****************************************************************/


OPTIONS LS=72;
TITLE 'GEOMETRIC MEANS';

DATA; 
   INPUT X Y Z@@; 
CARDS;
2 3 1 2 5 6 4 3 2 1 2 3 45 68 6 5 4 3 2 2 1
2 3 2 2 1  3 -46 7 765 4 33 2 2 32 3  5 5 3 2 25 4 32 23
4 3 2 32 32 23 4 4 -55 2 23 1 1 22 32 32
;
RUN;

DATA LOGS; 
   SET;
   ARRAY L (3) X Y Z;
   DO I=1 TO 3;
     IF L(I)>0 THEN L(I)=LOG(L(I));
             ELSE L(I)=.;
   END;
RUN;

PROC MEANS;
   VAR X Y Z;
   OUTPUT OUT=MEANLOGS MEAN=X1 Y1 Z1;
RUN;

DATA GEOMEAN; 
   SET MEANLOGS;
   ARRAY MLOG(3) X1 Y1 Z1;
   DO I=1 TO 3;
     MLOG(I)=EXP(MLOG(I));
   END;
RUN;

PROC PRINT;
RUN;
 
Also See Geometric Statistics in PK Analysis 
Geometric Statistics, geometric CV 

No comments: