Published on :
Data Manipulation CREATION_INTERNE

Handling Missing Values with the SUM Function

This code is also available in: Deutsch Español Français
Awaiting validation
This program illustrates a key behavior of the SUM function in SAS©: unlike simple arithmetic addition, the SUM function ignores missing values (treats them as 0) when calculating the total, ensuring that a numeric result is returned as long as at least one argument is non-missing.
Data Analysis

Type : CREATION_INTERNE


The 'cholesterol' data is generated directly in the code using the DATALINES statement.

1 Code Block
DATA STEP Data
Explanation :
Creation of a table named 'cholesterol'. The 'Total1' variable is calculated by adding 'Ldl', 'Hdl', and 'Vldl'. Observation 2 contains a missing value for 'Vldl', demonstrating that 'Total1' will still be calculated (205) thanks to the SUM function.
Copied!
1DATA cholesterol;
2 INPUT ID Ldl Hdl Vldl;
3 Total1 = SUM(Ldl, Hdl, Vldl);
4 DATALINES;
51 160 50 20
62 150 55 .
73 120 40 30
84 140 50 25
9;
10RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.