Lesson 2, Part 3: Handling Missing Values¶
Assigning a single character value to a missing value, that is, a dot (.)¶
In [6]:
ods html close;
options nocenter nodate nonumber MISSING='X' ;
data Example_M_Equal;
input x y z c name $;
format x y z c percent12.2;
datalines;
.38 .0324 1.0 .345 John
.12 . . .606 Carl
.15 .7476 . .049 Choi
. .22 . . Rubi
.35 . . . Beth
;
title 'Missing values (.) Assigned a Character Value';
proc print data=Example_M_Equal;
var name;
sum x y z c;
run;
| Obs | name | x | y | z | c |
|---|---|---|---|---|---|
| 1 | John | 38.00% | 3.24% | 100.00% | 34.50% |
| 2 | Carl | 12.00% | X | X | 60.60% |
| 3 | Choi | 15.00% | 74.76% | X | 4.90% |
| 4 | Rubi | X | 22.00% | X | X |
| 5 | Beth | 35.00% | X | X | X |
| 100.00% | 100.00% | 100.00% | 100.00% |
Using a MISSING statement¶
Note that the value M in the input data lines is to be considered a special missing value rather than an invalid numeric data value.
In [9]:
ods html close;
options nocenter nodate nonumber ;
data Example_M_C;
length state $20;
infile datalines FIRSTOBS=2;
input state N_Var1-N_Var4 ;
missing M;
datalines;
state N_Var1 N_Var2 N_Var3 N_Var4
Alabama 13.2 236 58 21.2
Alaska 10 263 48 M
Arizona 8.1 294 80 31
Arkansas 8.8 190 50 19.5
California 9 276 91 M
Colorado 7.9 M 78 38.7
Connecticut 3.3 110 77 11.1
;
title 'Missing values (.) Assigned a Character Value M';
title2 "by specefying M in the MISSING statement";
proc print data=Example_M_C noobs;
var state N_Var:;
run;
title;
| state | N_Var1 | N_Var2 | N_Var3 | N_Var4 |
|---|---|---|---|---|
| Alabama | 13.2 | 236 | 58 | 21.2 |
| Alaska | 10.0 | 263 | 48 | M |
| Arizona | 8.1 | 294 | 80 | 31.0 |
| Arkansas | 8.8 | 190 | 50 | 19.5 |
| California | 9.0 | 276 | 91 | M |
| Colorado | 7.9 | M | 78 | 38.7 |
| Connecticut | 3.3 | 110 | 77 | 11.1 |
Assign various special missing values to numeric variables¶
Examples: ._, .a., and .z
In [12]:
ods html close;
options nocenter nodate nonumber nosource;
data Example_M_S;
input x y z c name $;
format x y z c percent12.2;
datalines;
.38 .0324 1.0 .345 John
.12 .a .z .606 Carl
.15 .7476 .z .049 Choi
._ .22 .z . Rubi
.35 .a .z . Beth
;
title 'Special Types of Missing Values Printed';
proc print data=Example_M_S noobs;
var name;
sum x y z c;
run;
title;
| name | x | y | z | c |
|---|---|---|---|---|
| John | 38.00% | 3.24% | 100.00% | 34.50% |
| Carl | 12.00% | A | Z | 60.60% |
| Choi | 15.00% | 74.76% | Z | 4.90% |
| Rubi | _ | 22.00% | Z | X |
| Beth | 35.00% | A | Z | X |
| 100.00% | 100.00% | 100.00% | 100.00% |