FIRST_NOT_NULL(): return the first non-null value (type-preserving)

Modified on Mon, 2 Mar at 11:53 AM

first_not_null() scans several variables from left to right and returns the first value that is not null.
Unlike first_numeric_value(), it keeps the original variable type (List stays List, Yes-no stays Yes-no, Numeric stays Numeric).

This is useful whenever you have multiple possible sources for the same information and you want a simple fallback / priority rule.


Syntax

first_not_null(Var1, Var2, Var3, ...)
  • The function evaluates arguments from left to right

  • All inputs must have the same type:

    • all List, or all Yes-no, or all Numeric

  • Return type: same as the inputs

If all inputs are null, the result is null (shown as “NC” in the eCRF).


How it works

  1. Check Var1

  2. If Var1 is null, check Var2, then Var3, etc.

  3. Return the first non-null value found

If more than one input is non-null, the left-most one wins.


Example 1 (Numeric): prefer measured value, fallback to self-reported

Weight_Final = first_not_null(Weight_Measured, Weight_SelfReported, Weight_LastKnown)
  • Returns a Numeric value

  • Uses your preferred priority order


Example 2 (List): unify two form versions

If you updated a List question mid-study and now have two variables:

  • EmploymentStatus_v2 (List)

  • EmploymentStatus_v1 (List)

You can keep one stable analysis variable:

EmploymentStatus = first_not_null(EmploymentStatus_v2, EmploymentStatus_v1)

The output is a List value (same type as inputs).


Example 3 (Yes-no): fallback between sources

HasDiabetes = first_not_null(DiabetesReported, DiabetesInMedicalHistory)

Returns a Yes-no value using the first non-null source.


Important notes

  • Type consistency is not required.
    Arguments can be of different types, mixing List, Numeric, Yes-no and Event variables.
    However, this may lead to unexpected behaviors. If you want to ensure a consistent behavior, you may need to use a free-text variable as the output variable.

  • If all inputs are null, the result is null (displayed as “NC” in the eCRF).


Practical tips

  • Use first_not_null() when you want to keep the original type and labels.

  • Use first_numeric_value() when you want a Numeric output (e.g., to map across languages or standardize codes).

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article