How can the NMISS function be used in SAS and can you provide an example? 2

How can the NMISS function be used in SAS and can you provide an example?

The NMISS function in SAS is used to count the number of missing values in a data set. It is often used in data cleaning and analysis to identify missing data and handle it accordingly. The function can be applied to numeric and character variables, and it returns a count of the missing values.

For example, suppose we have a data set with a variable “age” and we want to know how many missing values are present in this variable. We can use the NMISS function as follows:

NMISS(age);
This will return the number of missing values in the “age” variable. The result can then be used to identify and handle the missing values in the data set.

Use the NMISS Function in SAS (With Example)


You can use the NMISS function in SAS to count the number of missing values for each numeric variable in a dataset.

Here is one common way to use this function in practice:

proc meansdata=my_data nmiss;
run;

This particular example will count the number of missing values for each numeric variable in the dataset called my_data.

The following example shows how to use NMISS in practice.

Example: Use NMISS in SAS to Count Number of Missing Values for Each Numeric Variable

Suppose we have the following dataset in SAS called my_data that contains information about various basketball players:

/*create dataset*/
data my_data;
    input team $ points assists rebounds;
    datalines;
A 10 2 .
A 17 5 .
A 17 . .
A 18 3 4
A 15 0 5
B . 4 5
B 29 0 8
B . 2 9
C 12 1 9
. 30 1 .
;
run;

/*view dataset*/
proc printdata=my_data;

Notice that there are missing values for each variable in the dataset.

We can use the NMISS function to count the number of missing values in each variable:

/*count number of missing values in each variable*/proc meansdata=my_data nmiss;
run;

NMISS function in SAS example

From the output table we can see:

  • The points variable has 2 missing values.
  • The assists variable has 1 missing value.
  • The rebounds variable has 4 missing values.

And so on.

By default, the NMISS function does not count the number of missing values for character variables in a dataset.

/*count number of missing values for team variable*/proc sql; 
    select nmiss(team) as missing_team_values
    from my_data;
quit;

From the output we can see that there is 1 missing value in the team column.

Note: You can find the complete documentation for the SAS NMISS function .

The following tutorials explain how to perform other common tasks in SAS:

Cite this article

stats writer (2024). How can the NMISS function be used in SAS and can you provide an example?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-the-nmiss-function-be-used-in-sas-and-can-you-provide-an-example/

stats writer. "How can the NMISS function be used in SAS and can you provide an example?." PSYCHOLOGICAL SCALES, 23 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-the-nmiss-function-be-used-in-sas-and-can-you-provide-an-example/.

stats writer. "How can the NMISS function be used in SAS and can you provide an example?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-the-nmiss-function-be-used-in-sas-and-can-you-provide-an-example/.

stats writer (2024) 'How can the NMISS function be used in SAS and can you provide an example?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-the-nmiss-function-be-used-in-sas-and-can-you-provide-an-example/.

[1] stats writer, "How can the NMISS function be used in SAS and can you provide an example?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.

stats writer. How can the NMISS function be used in SAS and can you provide an example?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

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