####
**Live Online Training :**
SAS Programming with 50+ Case Studies

- Explain Programming Concepts in Simple English

- Live Projects

- Scenario Based Questions

- Job Placement Assistance

- Get 10% off till Oct 26, 2017

- Batch starts from October 28, 2017

In SAS, Numeric and Character missing values are represented differently.

The following code checks for dot missing value only. It does not check for other 27 special numeric missing values (._ , .A through .Z)

Character missing values are represented by a single blank enclosed in quotes

Suppose we have a data set containing three variables - X, Y and Z. They all have some missing values. We wish to compute sum of all the variables.

SAS provides the statement CALL MISSING() to explicitly initialise or set a variable value to be missing.

By default, missing values are excluded and percentages are based on the number of non-missing values. If you use the

It produces statistics on non-missing data only. The NMISS option is used to calculate number of missing values.

By default, correlations are computed based on the number of pairs with non-missing data (pairwise deletion of missing data). The nomiss option can be used on the proc corr statement to request that correlations be computed only for observations that have non-missing data for all variables on the var statement (listwise deletion of missing data).

If any of the variables on the model or var statement are missing, they are excluded from the analysis (i.e., listwise deletion of missing data)

If any of the variables on the model or var statement are missing, they are excluded from the analysis (i.e., listwise deletion of missing data)

Missing values are deleted listwise, i.e., observations with missing values on any of the variables in the analysis are omitted from the analysis.

**Numeric Missing Values****SAS stores 28 missing values in a numeric variable.**

**They are as follows :**- dot-underscore
**. _** - dot
**.** **.**A through**.**Z ( Not case sensitive)

**Sorting Order :**dot- underscore is the lowest valued missing value. After the dot-underscore, comes the dot, and then the dot-A. The dot-Z is the highest valued missing value.

*Run the following code and see how SAS treats them missing value*data temp;

input x;

cards;

1

2

3

.

.A

.X

.Z

._

4

;

run;

proc freq;

table x;

run;

**Check for missing numeric values**

If x =. then PUT "x is missing";

The following code checks for all 28 numeric missing values (. , ._ , .A through .Z)

If x <=.z then PUT "x is missing";

The

**MISSING**function accepts either a character or numeric variable as the argument and returns the value 1 if the argument contains a missing value or zero otherwise.If missing(x) then PUT "x is missing";

**Character missing values**

**' '**.

If y = ' ' then put "y is missing";

If missing(y) then put "y is missing";

**Working with Missing Values**

Suppose we have a data set containing three variables - X, Y and Z. They all have some missing values. We wish to compute sum of all the variables.

data mydata2;

set mydata;

a=sum(x,y,z);

p=x+y+z;

run;

**SUM**function returns the sum of non-missing arguments whereas

**“+”**operator returns a missing value if any of the arguments are missing.

**Functions that handle MISSING data**

**NMISS :**The NMISS() function will return the number of missing values in the specified list of numeric variables. The NMISS() function will convert any character values to numeric before assessing if the argument value is missing.

IF NMISS(x,y,z) = 0 then PUT " All variables have non-missing values";

**CMISS :**The CMISS() function introduced in SAS 9.2 is similar to the NMISS() function that it counts the number arguments that are missing, but for both character and numeric variables without requiring character values to be converted to numeric.**N :**The N() function returns the number of non-missing values in a list of numeric variables.**CALL MISSING**SAS provides the statement CALL MISSING() to explicitly initialise or set a variable value to be missing.

data _null_;call missing( num_1, num_2, x );num_3 = x;

put num_1 = / num_2 = / num_3 = ;

run;

**Delete empty rows**

options missing = ' ';

data readin;

set outdata;

if missing(cats(of _all_)) then delete;

run;

**How missing values are handled in SAS procedures****1. PROC FREQ**

By default, missing values are excluded and percentages are based on the number of non-missing values. If you use the

**"/ MISSING"**option on the tables statement, the percentages are based on the total number of observations (non-missing and missing) and the percentage of missing values are reported in the table.PROC FREQ DATA= TEST;

TABLES X /MISSING;

RUN;

**2. PROC MEANS**

It produces statistics on non-missing data only. The NMISS option is used to calculate number of missing values.

Proc Means Data = test N NMISS;To see number of observations having a missing value for the classification variable, type

Var q1 - q5 ;

Run;

**MISSING**option in PROC MEANS.

Proc Means data = test N NMISSMISSING;

Class Age ;

Var q1 - q5;

Run;

**3. PROC CORR**

By default, correlations are computed based on the number of pairs with non-missing data (pairwise deletion of missing data). The nomiss option can be used on the proc corr statement to request that correlations be computed only for observations that have non-missing data for all variables on the var statement (listwise deletion of missing data).

**4. PROC REG**

If any of the variables on the model or var statement are missing, they are excluded from the analysis (i.e., listwise deletion of missing data)

**5. PROC LOGISTIC**

If any of the variables on the model or var statement are missing, they are excluded from the analysis (i.e., listwise deletion of missing data)

**6. PROC FACTOR**

Missing values are deleted listwise, i.e., observations with missing values on any of the variables in the analysis are omitted from the analysis.

Thanks a lot! This blog has been very helpful.

ReplyDeleteThanks, the information was really helpful.

ReplyDeleteI tried this code with the temp data but its not removing any rows.

ReplyDeleteoptions missing = ' ';

data readin;

set outdata;

if missing(cats(of _all_)) then delete;

run;

Output is same as the data set. Is it working for any one else ?