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 allYes-no, or allNumeric
Return type: same as the inputs
If all inputs are null, the result is null (shown as “NC” in the eCRF).
How it works
Check
Var1If
Var1is null, checkVar2, thenVar3, etc.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, mixingList,Numeric,Yes-noand 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
Feedback sent
We appreciate your effort and will try to fix the article