LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (April 1996, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 23 Apr 1996 13:53:06 +0100
Reply-To:     John Whittington <johnw@MAG-NET.CO.UK>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         John Whittington <johnw@MAG-NET.CO.UK>
Subject:      Re: Geometric Row Mean
Comments: cc: Feldesmanm@pdx.edu

Yesterday I posted the following code for geometric mean:

> array x(*) x1 - x40 ; > prod = 1 ; > do i = 1 to 40 ; > prod = prod * x(i) ; > end ; > gmean = prod / 40 ;

The final line of the code segment obviously should have read:

gmean = prod**(1/40) ;

Sorry if I confused anyone. Following exchanges with the original questionner, I would add a few other comments/varaints to this:

1...If the variables of interest do not have numeric suffices but are known to be in consecutive positions in the PDV (with first and last known), one can code:

array x(*) apple -- tomato ;

[ if needs be, the ordering of variables in PDV can be forced by a RETAIN statement at the top of the DATA step]

2...If one is wanting to calculate the geometric mean of all numeric variables in the dataset, then one can code:

array x(*) _numeric_ ;

3...If either (1) or (2) above is used, the array declaration must come *after* the variables are all initialised (e.f. by a SET).

4...If missing data may be present and one wants to calculate the geometric mean of all non-missing values within the list of variables, then one can extend the code as follows, generalised for any number of variables:

array x(*) x1 - x40 ; /* or other variable list specifications */ prod = 1 ; do i = 1 to dim(x) ; if x(i) ne . then prod = prod * x(i) ; end ; gmean = prod ** ( 1 / n(of x(*))) ;

John

----------------------------------------------------------- Dr John Whittington, Voice: +44 1296 730225 Mediscience Services Fax: +44 1296 738893 Twyford Manor, Twyford, E-mail: johnw@mag-net.co.uk Buckingham MK18 4EL, UK CompuServe: 100517,3677 -----------------------------------------------------------


Back to: Top of message | Previous page | Main SAS-L page