How can I select observations that are not null using the SAS method? 2

How can I select observations that are not null using the SAS method?

The SAS method is a programming language commonly used for statistical analysis and data management. One useful function of SAS is the ability to select observations that are not null, meaning they have a valid value or are not empty. This can be done by using the “where” statement in SAS, which allows the user to specify certain criteria for selecting data. By including the “where” statement with the condition “is not null,” the user can filter out any observations that do not meet this criteria. This allows for more accurate and efficient data analysis by focusing only on relevant and complete data. Overall, the SAS method provides a reliable and straightforward way to select observations that are not null, ensuring the quality and accuracy of statistical analyses.

SAS: Select Observations Which are Not Null


You can use the following basic syntax to select observations in a dataset in SAS where a certain column value is not null:

/*select only rows where var1 is not null*/
proc sql;
	select *
	from my_data1
	where not missing(var1);
quit;

The following example shows how to use this syntax in practice.

Example: Select Observations Which are Not Null in SAS

Suppose we have the following dataset in SAS:

/*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 printdata=my_data1;

Notice that there are some null values in the points column.

We can use the following code to select all of the rows where the value in the points column is not null:

/*select only rows where points is not blank*/
proc sql;
	select *
	from my_data1
	where not missing(points);
quit;

Notice that only the rows where the value in the points column is not null are returned.

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:

/*count rows where points is not blank*/
proc sql;
	select count(*)
	from my_data1
	where not missing(points);
quit;

This tells us that 6 observations in the dataset have a value that is not null in the points column.

Additional Resources

Cite this article

stats writer (2024). How can I select observations that are not null using the SAS method?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-select-observations-that-are-not-null-using-the-sas-method/

stats writer. "How can I select observations that are not null using the SAS method?." PSYCHOLOGICAL SCALES, 1 Jul. 2024, https://scales.arabpsychology.com/stats/how-can-i-select-observations-that-are-not-null-using-the-sas-method/.

stats writer. "How can I select observations that are not null using the SAS method?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-select-observations-that-are-not-null-using-the-sas-method/.

stats writer (2024) 'How can I select observations that are not null using the SAS method?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-select-observations-that-are-not-null-using-the-sas-method/.

[1] stats writer, "How can I select observations that are not null using the SAS method?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, July, 2024.

stats writer. How can I select observations that are not null using the SAS method?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top