Table of Contents
In data analysis, particularly when working with large or complex datasets, handling missing data is a critical step for ensuring the integrity and reliability of statistical results. Missing values, often represented by blanks or specific symbols (like a single period `.` for numeric variables in SAS), can skew summaries, invalidate models, and lead to incorrect conclusions if not addressed properly. One of the most common tasks a data analyst faces is the need to filter a dataset to include only those observations where a specific variable contains a valid, non-null entry.
Fortunately, the PROC SQL procedure in SAS provides an extremely efficient and intuitive mechanism for this exact purpose. By leveraging the built-in MISSING function within the WHERE clause, we can quickly select observations where a certain column value is present (i.e., not null). This method is highly favored due to its similarity to standard SQL syntax, making it accessible to users familiar with database query languages.
The Core Syntax for Filtering Non-Null Data using PROC SQL
The standard methodology for excluding rows containing missing values for a particular variable involves using the NOT MISSING() structure within a WHERE clause. This structure checks each row against the specified variable and returns only those where the variable holds a value. This approach works seamlessly for both numeric and character data types in SAS, as the MISSING function is designed to detect SAS’s internal representations of missingness.
The fundamental syntax is straightforward. Here, we demonstrate how to select all columns (using select *) from a dataset named my_data1, retaining only the rows where the variable var1 is not missing. This is a foundational technique for cleaning and preparing datasets prior to advanced statistical modeling.
/*select only rows where var1 is not null*/
proc sql;
select *
from my_data1
where not missing(var1);
quit;Understanding the application of this syntax is crucial for data manipulation in SAS. The following example provides a practical demonstration of how to apply this filtering method to a sample dataset containing deliberate missing entries, showcasing the resulting cleaned output.
Example: Setting Up the Sample Dataset in SAS
To illustrate the effectiveness of the WHERE NOT MISSING() clause, we must first establish a simple dataset. This dataset, named my_data1, simulates raw data collection where entries for the points variable might occasionally be absent. In SAS, numeric missing values are denoted by a single period (.) when entered via datalines or when printed.
Suppose we have the following sample dataset in SAS, representing team scores:
/*create dataset*/
data my_data1;
input team $ points;
datalines;
A 15
B .
C 22
D 19
E 29
F .
G 40
H 35
;
run;
/*view dataset*/
proc print data=my_data1;
When this code is executed using PROC PRINT, the resulting table clearly shows the original structure, including the entries marked as missing. It is important to notice these missing entries as they are the targets for our subsequent filtering operation. The visualization below confirms the presence of missing data in the points column, specifically for teams B and F, represented by the period symbol.

Notice carefully that there are two null values in the points column. Our goal is to isolate only the rows that contain valid, recorded score data, thereby cleaning the dataset for meaningful analysis.
Applying PROC SQL to Select Non-Null Observations
With the sample data established, we can now implement the filtering logic using PROC SQL. The procedure uses the WHERE NOT MISSING(points) statement to instruct SAS to exclude any record where the points variable contains a missing value. This ensures that only complete observations are retained in the resulting temporary table. This is often the first step in preparing high-quality data subsets.
We use the following code to select all of the rows where the value in the points column is not null, effectively eliminating teams B and F from our analysis:
/*select only rows where points is not blank*/
proc sql;
select *
from my_data1
where not missing(points);
quit;The resulting output clearly demonstrates the power of this filtering technique. Only the six teams for which score data was successfully recorded are displayed. The observations corresponding to missing values have been successfully excluded, providing a clean subset ready for further statistical computation or reporting.

Notice that only the rows where the value in the points column is not null are returned. This confirms that the filtering logic using the MISSING function worked as intended, effectively isolating the valid data points.
Alternative and Advanced Techniques for Handling Missing Data
While the NOT MISSING() function within PROC SQL is highly efficient for simple filtering, SAS offers alternative methods, such as using the Data Step, especially when more complex conditional logic or data manipulation is required alongside the selection process. For numeric variables, you could use the direct comparison WHERE points IS NOT NULL, though relying on MISSING() is often preferred as it handles special numeric missing values (A-Z) seamlessly.
For character variables, the MISSING() function checks for a blank string. However, an alternative popular method for filtering character data in SQL is to check for non-empty strings using syntax like WHERE var1 NE ' ' (where NE means “not equal to”). Regardless of the variable type, the MISSING() function remains the most robust and universally applicable method in SAS.
Beyond simple selection, analysts often need to summarize the extent of missingness. The ability to count the number of non-null observations is a common requirement for data quality reporting. We can easily integrate the COUNT() aggregate function within PROC SQL alongside our existing filtering condition to achieve this.
Note that you could also use the count() function in proc sql to count the number of observations where the value in the points column is not null, providing a quick summary statistic:
/*count rows where points is not blank*/
proc sql;
select count(*)
from my_data1
where not missing(points);
quit;This code returns a single value representing the total count of valid observations, which is an invaluable metric when assessing data completeness.
![]()
This output tells us clearly that 6 observations in the dataset have a value that is not null in the points column, aligning perfectly with the six non-missing rows we observed in the previous step.
Best Practices for Data Integrity and Missing Value Handling
Systematically addressing missing data is a cornerstone of responsible data management. While filtering out null values is often necessary, understanding the context of the missingness is equally important. If missing values are not random (Missing Not At Random – MNAR), simply excluding them (listwise deletion) can introduce bias into your analysis. Therefore, best practices dictate a thorough investigation before deletion.
When working with non-null selection in SAS, consider the following best practices:
- Documentation: Always document the reason for filtering out missing values. If imputation methods are used instead of deletion, document the imputation strategy.
- Type Awareness: Be mindful of the data type. While
MISSING()handles both numeric (.) and character (empty string' '), ensure that non-standard missing representations (e.g., using-99as a proxy for missing) are handled explicitly either before or during the filtering process. - Efficiency: For simple filtering, PROC SQL utilizing the
WHERE NOT MISSING()syntax is generally the most concise and efficient method for large datasets, particularly when compared to complex Data Step conditional processing.
Mastering the use of the MISSING() function within SQL is a fundamental skill for any SAS programmer dedicated to producing clean and accurate statistical output.
Additional Resources
For those looking to deepen their understanding of data handling and quality control in SAS, exploring the documentation regarding the Data Step, advanced SQL queries, and specialized missing value functions is highly recommended. These resources provide context on how SAS internally manages data types and null representations, which is key to troubleshooting complex data issues.
The concepts discussed here form the baseline for robust data preparation, ensuring that analyses are conducted only on valid observations.
Cite this article
Mohammed looti (2025). Learning to Filter Non-Null Values in SAS Datasets. PSYCHOLOGICAL STATISTICS. Retrieved from https://statistics.arabpsychology.com/sas-select-observations-which-are-not-null/
Mohammed looti. "Learning to Filter Non-Null Values in SAS Datasets." PSYCHOLOGICAL STATISTICS, 31 Oct. 2025, https://statistics.arabpsychology.com/sas-select-observations-which-are-not-null/.
Mohammed looti. "Learning to Filter Non-Null Values in SAS Datasets." PSYCHOLOGICAL STATISTICS, 2025. https://statistics.arabpsychology.com/sas-select-observations-which-are-not-null/.
Mohammed looti (2025) 'Learning to Filter Non-Null Values in SAS Datasets', PSYCHOLOGICAL STATISTICS. Available at: https://statistics.arabpsychology.com/sas-select-observations-which-are-not-null/.
[1] Mohammed looti, "Learning to Filter Non-Null Values in SAS Datasets," PSYCHOLOGICAL STATISTICS, vol. X, no. Y, ص Z-Z, October, 2025.
Mohammed looti. Learning to Filter Non-Null Values in SAS Datasets. PSYCHOLOGICAL STATISTICS. 2025;vol(issue):pages.