One is sometimes precluded from using the geometric mean to descrtibe the location of data by the presence of zeros. SAS estimates the geometric mean as zero when there are zeros in the data. Here is a reasonable alternative:
/* A simple SQL implementation of a generalised geometric mean
for cases when the data contains some zeros. The GEOMEAN function from SAS
returns zero if any of the data is zero. The generalised geometric
mean is computed as a weighted average of zero and the geometric mean
of positive values.
This estimator was proposed by:
Habib, Elsayed A. E. (2012) Geometric mean for negative and zero values.
IJRRAS 11 (3), p. 419-432.
This implementation accounts for negative values by treating them as if
they were zeros.
*/
title "Estimators of the geometric mean for the set {0, 1, 2, 3, 4}";
data test;
do x = 0 to 4;
output;
end;
run;
proc sql;
select
case when min(x) <= 0 then 0 else exp(mean(log(x))) end
as geoMean "Standard SAS geometric mean",
exp(mean(log(x)))
as geoMeanPos "Geometric mean of positive values",
exp(mean(log(x))) * count(log(x)) / count(x)
as geoMean0 "Weighted average geometric mean"
from test;
quit;
Standard SAS geometric mean |
Geometric mean of positive values |
Weighted average geometric mean |
0 | 2.213364 | 1.770691 |
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.