Wednesday, June 25, 2014

Easily Count Missing Values in SAS

If counting the number of missing values among groups of variables is the task (something I had to do today), then using PROC FORMAT seems to be the easiest and most efficient method if the variables are character whereas if the variables are numeric, PROC MEANS is a good approach.  The code snippet below was borrowed from "Cody's Data Cleaning Techniques Using SAS Software" by Ron Cody.  

Character Variables:

* **format for missing vs. non-missing values;
proc format;
  value $misscnt
    ' ' = 'Missing'
    OTHER = 'Non-Missing';
run;

proc freq data=dsin;
  tables _character_ / nocum missing;
  format _character_ $misscnt.;
run;


And for numeric variables:

proc means data=dsin n nmiss;
  var _numeric_;
run;


It really can't get much simpler than this.  

No comments:

Post a Comment