Table of Contents
The MISSING function in SAS is used to determine if a value is missing or not. It can be applied to both numeric and character variables. When applied to a numeric variable, the MISSING function returns a value of 1 if the variable is missing, and 0 if it is not. Similarly, when applied to a character variable, it returns a value of 1 if the variable is missing, and 0 if it is not. This function is particularly useful in data cleaning and data analysis tasks, as it allows for easy identification and handling of missing values. It can also be used in conditional statements and data manipulations to filter out or replace missing values. Overall, the MISSING function is an essential tool for ensuring the accuracy and completeness of data in SAS.
Use the MISSING Function in SAS (With Examples)
You can use the MISSING function in SAS to check if a variable contains a missing value.
This function uses the following syntax:
MISSING(expression)
where:
- expression: The name of a character or numeric variable
This function will return 0 if the variable does not contain a missing value or 1 if it does contain a missing value.
The following example shows how to use this function in practice.
Example: How to Use the MISSING Function in SAS
Suppose we have the following dataset in SAS that contains information about various basketball players:
/*create dataset*/
data my_data;
input team $ position $ points assists;
datalines;
A Guard 14 4
A Guard 22 6
A Guard 24 9
A Forward 13 8
A Forward 13 9
A . 10 5
B Guard 24 4
B Guard . 6
B Forward 34 2
B Forward 15 5
B Forward 23 5
B . 10 4
;
run;
/*view dataset*/
proc printdata=my_data;
We can create a new dataset and use the MISSING function to create a variable that checks if each row in the position column is missing a value or not:
/*create new dataset*/
data new_data;
set my_data;
missing_position = missing(position);
run;
/*view new dataset*/
proc printdata=new_data;
The new column called missing_position contains a value of 0 if there is no missing value in the position column and a value of 1 if there is a missing value.
Note: Although row 8 has a missing value in the points column, the missing_position column contains a value of 0 because there is no missing value in the position column.
Also note that you can use an IF ELSE function with the MISSING function to return values other than 0 and 1.
/*create new dataset*/
data new_data;
set my_data;
if missing(position) then missing_position = 'yes';
else missing_position = 'no';
run;
/*view new dataset*/
proc printdata=new_data;
The new column called missing_position contains a value of no if there is no missing value in the position column and a value of yes if there is a missing value.
Note: You can find the complete documentation for the SAS MISSING function .
The following tutorials explain how to perform other common tasks in SAS:
Cite this article
stats writer (2024). How can the MISSING function be used in SAS?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-the-missing-function-be-used-in-sas/
stats writer. "How can the MISSING function be used in SAS?." PSYCHOLOGICAL SCALES, 23 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-the-missing-function-be-used-in-sas/.
stats writer. "How can the MISSING function be used in SAS?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-the-missing-function-be-used-in-sas/.
stats writer (2024) 'How can the MISSING function be used in SAS?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-the-missing-function-be-used-in-sas/.
[1] stats writer, "How can the MISSING function be used in SAS?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can the MISSING function be used in SAS?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
