From 357b07fe8c32b8d3e669687551b2cca5dea9eed5 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sun, 28 Aug 2022 14:14:56 -0700 Subject: [PATCH] variable: Also complain about negative weights in var_force_valid_weight(). --- src/data/variable.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/data/variable.c b/src/data/variable.c index 8acac77fb2..8867ba4bae 100644 --- a/src/data/variable.c +++ b/src/data/variable.c @@ -1326,15 +1326,16 @@ var_clear_vardict (struct variable *v) double var_force_valid_weight (const struct variable *wv, double w, bool *warn_on_invalid) { - if (w < 0.0 || (wv && var_is_num_missing (wv, w))) - w = 0.0; - - if (w == 0.0 && warn_on_invalid != NULL && *warn_on_invalid) + if (w <= 0.0 || (wv ? var_is_num_missing (wv, w) : w == SYSMIS)) { - *warn_on_invalid = false; - msg (SW, _("At least one case in the data file had a weight value " - "that was user-missing, system-missing, zero, or " - "negative. These case(s) were ignored.")); + w = 0.0; + if (warn_on_invalid != NULL && *warn_on_invalid) + { + *warn_on_invalid = false; + msg (SW, _("At least one case in the data file had a weight value " + "that was user-missing, system-missing, zero, or " + "negative. These case(s) were ignored.")); + } } return w; -- 2.30.2