Reputation: 1
I am working on a SAS Dataset
which has missing values.
I can identify whether a particular variable has missing values using IS NULL/IS MISSING
operator.
Is there any alternative way, through which I can identify which variables have missing values in one shot.
Thanks in Advance
Upvotes: 0
Views: 1826
Reputation: 43
Two options (in addition to Peter Slezák's) I can suggest are : - Use proc means with nmiss
proc means data = ___ n nmiss;
var _numeric_;
run;
Hope this helps, regards, Sundaresh
Upvotes: 2
Reputation: 11
You can use proc freq table statement with missing option. It includes missing category if missing values exist. Useful for categorical data.
data example;
input A Freq;
datalines;
1 2
2 2
. 2
;
*list variables in tables statement;
proc freq data=example;
tables A / missing;
run;
You can also use Proc Univariate it creates MissingValues table in ODS by default if any missing values exist. Useful for numeric data.
Upvotes: 1
Reputation: 51611
The syntax IS NULL
or IS MISSING
is limited to use in SQL code (also in WHERE
statements or WHERE=
dataset options since those essentially use the same parser.)
To test if a value is missing you can also use the MISSING()
function. Or compare it to a missing value. So for character variables test if it is equal to all blanks: c=' '
. For numeric you can test x=.
, but you also need to look out for special missing values. So you might test if x <= .z
.
To get a quick summary of number of distinct missing values for each variable you could use the NLEVEL option on PROC FREQ. Note it might not work for a large dataset with too many distinct values as the procedure will run out of memory.
Upvotes: 2
Reputation: 3315
use array and vname to find variable with missing values. If you want rows with missing values use cmiss function.
data have;
infile datalines missover;
input id num char $ var $;
datalines;
1 . A C
2 3 D
5 6 B D
;
/* gives variables with missing values*/
data want1(keep=miss);
set have;
array chars(*) _character_;
array nums(*) _numeric_;
do i=1 to dim(chars);
if chars(i)=' ' then
miss=vname(chars(i));
if nums(i)=. then
miss=vname(nums(i));
end;
if miss=' ' then
delete;
run;
/* gives rows with missing value*/
data want(drop=rows);
set have;
rows=cmiss(of id -- var);
if rows=1;
run;
Upvotes: 1