Sample 24673: Determine the MEDIAN value prior to SAS 9.0
Determine the middle of a distribution.
Note:
If you are running a release of SAS prior to SAS 9.0,
you can determine the median value of a group by using
the ORDINAL function to mimic the MEDIAN function.
The syntax of the ORDINAL function is :
ORDINAL(count,argument,argument, . . .) ;
The ORDINAL function returns the count-th largest of the
arguments, beginning with the lowest value. For
instance, if you specify 4 as the value of the count
parameter, ORDINAL will return the 4th largest value in
the series of variables or values in the argument list.
With an odd number of variables, the median will be the
single value that falls at the midpoint of the
distribution. See Sample 1 on the Full Code tab.
With an even number of variables, there is no single
middle value, therefore the median will be the average
of the two middle values in the ordered distribution.
See Sample 2 on the Full Code tab.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
/* Sample 1: Odd number of variables in the distribution */
data test;
array x{9} x1-x9;
/* Generate 9 variables, 5 observations */
do i=1 to 5;
do j=1 to 9;
x{j}=ceil(ranuni(123)*10);
end;
output;
end;
drop i j;
run;
data test;
set test;
median=ordinal(5,x1,x2,x3,x4,x5,x6,x7,x8,x9);
run;
proc print data=test;
run;
/* Sample 2: Even number of variables in the distribution */
data test2;
array x{10} x1-x10;
/* Generate 10 variables, 5 observations */
do i=1 to 5;
do j=1 to 10;
x{j}=ceil(ranuni(123)*10);
end;
output;
end;
drop i j;
run;
data test2;
set test2;
median=(ordinal(5,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10)
+ ordinal(6,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10))/2;
run;
proc print data=test2;
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
Sample 1: Odd number of variables in the distribution
Obs x1 x2 x3 x4 x5 x6 x7 x8 x9 median
1 8 4 2 10 4 3 8 4 2 4
2 2 8 5 10 3 8 6 6 9 6
3 2 9 7 8 8 4 6 10 1 7
4 7 7 4 6 4 6 3 6 6 6
5 1 2 6 7 5 2 8 10 8 6
Sample 2: Even number of variables in the distribution
Obs x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 median
1 8 4 2 10 4 3 8 4 2 2 4.0
2 8 5 10 3 8 6 6 9 2 9 7.0
3 7 8 8 4 6 10 1 7 7 4 7.0
4 6 4 6 3 6 6 1 2 6 7 6.0
5 5 2 8 10 8 10 1 7 9 3 7.5
Determine the middle of a distribution.
Type: | Sample |
Topic: | SAS Reference ==> DATA Step SAS Reference ==> Functions
|
Date Modified: | 2005-12-23 03:02:57 |
Date Created: | 2004-09-30 14:09:03 |
Operating System and Release Information
SAS System | Base SAS | All | n/a | n/a |