DATA Step, Macro, Functions and more

Missing Percentage for each variable

Accepted Solution Solved
Reply
Regular Contributor
Posts: 181
Accepted Solution

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
Respected Advisor
Posts: 3,777

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 Smiley Tonguemisslist separated by ' '
     
from nmiss where nmiss/(sum(n,nmiss)) ge .15;
  
quit;
  
run;
%put NOTE: &=PMISSLIST;     

View solution in original post


All Replies
Valued Guide
Posts: 858

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
Respected Advisor
Posts: 3,777

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 Smiley Tonguemisslist separated by ' '
     
from nmiss where nmiss/(sum(n,nmiss)) ge .15;
  
quit;
  
run;
%put NOTE: &=PMISSLIST;     
Regular Contributor
Posts: 181

Re: Missing Percentage for each variable

How can i replicate the same for character variables? PROC MEANS does not work for character variables and PROC FREQ produces clumsy output. Thanks in anticipation!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 389 views
  • 0 likes
  • 3 in conversation