Date: Wed, 25 Apr 2007 11:58:15 -0400
Reply-To: Magdalena Tolea <MTOLEA@EPI.UMARYLAND.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Magdalena Tolea <MTOLEA@EPI.UMARYLAND.EDU>
Subject: Re: calculation of mean when number of measurement points varies
Content-Type: text/plain; charset=US-ASCII
Problem solved. Thank you Jack and Matthew.
University of Maryland, Baltimore
DEPM/Gerontology PhD Program
MSTF room 311A
>>> Jack Clark <JClark@CHPDM.UMBC.EDU> 4/25/2007 10:50 AM >>>
I would use the MEAN function in a DATA step. This logic makes sure
there is at least one non-missing value. It should ignore other
potential missing values and calculate the mean based on non-missing
If nmiss(of sbp1-sbp4) lt 4 then meansbp = mean(of sbp1-sbp4);
Else meansbp = .;
If nmiss(of dbp1-dbp4) lt 4 then meandbp = mean(of dbp1-dbp4);
Else meandbp = .
Center for Health Program Development and Management
University of Maryland, Baltimore County
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
Sent: Wednesday, April 25, 2007 10:35 AM
Subject: calculation of mean when number of measurement points varies
Using NHANES data, I would like to calculate mean systolic blood
and mean diastolic blood pressure (per individual) for up to four
measurement times. However, the number of and the sequence of these
vary. Is there an easy way to come up with these means, which would only
the valid values, such that if someone has only one measurement then the
mean takes that value, if they have two measurements done then the mean
takes into account the two and so on?
I would like to see something like,
id sbp1 dbp1 sbp2 dbp2 sbp3 dbp3 sbp4 dbp4 meansbp meandbp
21005 . . . . . . . . . .
21006 100 58 94 46 102 54 . . 99 53
21007 . . . . 96 62 . . 96 62
21008 . . 102 80 . . 104 74 103 77
21009 124 88 124 86 112 84 . . 120 86
21010 128 86 138 82 134 84 . . 133 84
21011 . . . . . . . . . .
21012 126 64 120 66 122 64 . . 123 65
21013 108 64 108 66 108 68 . . 108 66
Thank you in advance,
This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.