Sorry to pollute the interwebs but I liked this so much that I wrote a macro for myself.
1. It counts the number of missing vales for all variables in a dataset--both numeric and character
2. Prints a pattern of missingness for all variables that have at least one missing value starting on the left with the most-missing variable and displaying variables to the right with decreasing amount of missingness.
Maybe some of you will find it useful:
%macro Missingness(LibName,MemName);
proc format;
value missing .='M' other = ' ';
value $missing ' '='M' other = ' ';
run;
proc sql noprint;
select cat('sum(cmiss(',strip(Name),'))',' as ',strip(Name)) into :CVars separated by ','
from dictionary.columns
where libname=upcase("&LibName") AND memname=upcase("&MemName")
AND Type='char'
;
select cat('nmiss(',strip(Name),')',' as ',strip(Name)) into :NVars separated by ','
from dictionary.columns
where libname=upcase("&LibName") AND memname=upcase("&MemName")
AND Type='num'
;
create table missingness as
select &CVars, &NVars
from SASHelp.Heart;
quit;
proc transpose data=missingness
out=MissingT(rename=(_Name_=Variable Col1=NMiss));
format NMiss comma.;
run;
proc sql;
select * from MissingT order by NMiss desc
;
reset noprint
;
select Variable into :Vars separated by '*'
from MissingT
where NMiss GT 0
order by NMiss desc
;
drop table Missingness ; quit;
proc freq data=&LibName..&MemName;
tables &Vars / list missing;
format _character_ $missing. _numeric_ missing.;
run;
%mend Missingness;
... View more