Date: Wed, 5 May 2004 12:26:25 -0500
Reply-To: Robin High <robinh@UNLSERVE.UNL.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Robin High <robinh@UNLSERVE.UNL.EDU>
Subject: Re: Calculate medians for individual observations!
In-Reply-To: <OF1AB0FFE8.CEA66ECE-ON85256E8B.005BE7AB-85256E8B.005BA375@us.sanofi.com>
Content-Type: TEXT/PLAIN; charset=US-ASCII
Hello,
The post I just sent assumes no missing data in v1-vm. If missing values
do occur in the data then a little more calculation is needed to get the
median of the data available. You still apply the ORDINAL function, but
now need to determine the number of non-missing observations. If the
number of non-missing argument is even, then the median is between two
ordinals. Thus:
DATA two;
SET yourdata;
nonmiss = N(of v1-v5); * N counts the number of non-missing data;
ord1 = FLOOR((nonmiss+1)/2); * FLOOR is the closest integer less than
the value;
ord2 = CEIL((nonmiss+1)/2); * CEIL is the closest integer greater than
the value;
if ord1=ord2 then
median = ORDINAL(ord1, of v1-v5);
else
median = (ORDINAL(ord1, of v1-v5)
+ ORDINAL(ord2, of v1-v5)) / 2;
run;
Be sure to enter 'of v1-v5' in the ORDINAL function -- otherwise, you will
compute something you don't expect. The ORDINAL function may not be
extremely efficient, yet on fast computers it works quite well for small
datasets.
Robin High,
Univ. of Oregon
|