## Missing Percentage for each variable

Solved
Regular Contributor
Posts: 185

# Missing Percentage for each variable

I am trying to create a macro that drops all the variables having missing value % greater than 80. I have written a small code to get it started. But i am stuck how to take it forward.

data have;

set sashelp.class;

if _n_ in (5,10,12) then do;

call missing(height,weight);

end;

if _n_ in (7,9) then do;

call missing(age);

end;

run;

proc means data=have noprint;

var _numeric_;

output out=temp (drop=_type_) nmiss=;

run;

Accepted Solutions
Solution
‎05-04-2015 11:01 AM
Posts: 3,852

## Re: Missing Percentage for each variable

You want to know the names of the variables that have more than some percentage missing?

data have;
set sashelp.class;
if _n_ in (5 10 12) then do;

call missing(height,weight);
end;

if _n_ in (7 9) then do;

call missing(age);
end;
r = ranuni(
1);
run;
ods output summary=nmiss;
proc means data=have stackods nmiss n;

var _numeric_;
run;
ods output close;
proc print data=nmiss;
run;

%let pmisslist=;
proc sql noprint;

select variable into misslist separated by ' '

from nmiss where nmiss/(sum(n,nmiss)) ge .15;

quit;

run;
%put NOTE: &=PMISSLIST;

All Replies
Valued Guide
Posts: 864

## Re: Missing Percentage for each variable

I'm not sure if this is what you want, let me know:

data have;

set sashelp.class;

if _n_ in (5,10,12) then do;

call missing(height,weight);

end;

if _n_ in (7,9) then do;

call missing(age);

end;

run;

data want;

set have;

if missing(height) or missing(weight) then delete;

run;

Solution
‎05-04-2015 11:01 AM
Posts: 3,852

## Re: Missing Percentage for each variable

You want to know the names of the variables that have more than some percentage missing?

data have;
set sashelp.class;
if _n_ in (5 10 12) then do;

call missing(height,weight);
end;

if _n_ in (7 9) then do;

call missing(age);
end;
r = ranuni(
1);
run;
ods output summary=nmiss;
proc means data=have stackods nmiss n;

var _numeric_;
run;
ods output close;
proc print data=nmiss;
run;

%let pmisslist=;
proc sql noprint;

select variable into misslist separated by ' '

from nmiss where nmiss/(sum(n,nmiss)) ge .15;

quit;

run;
%put NOTE: &=PMISSLIST;
Regular Contributor
Posts: 185