**以excel的形式输出该数据集及其空变量的名称;
**database为逻辑库名称需要全大写,path为输出excel的路径及其名称;
%macro check_null(database,path);
proc sql noprint;
select count(memname) into:n trimmed from dictionary.tables where libname="&database.";
select memname into:r1 - :r&n from dictionary.tables where libname="&database.";
quit;
%do i = 1 %to &n;
proc sql noprint;
select count(name) into:d trimmed from dictionary.columns where libname="&database." and memname="&&r&i.";
select name into:s1 - :s&d from dictionary.columns where libname="&database." and memname="&&r&i.";
quit;
%do p=1 %to &d;
proc freq data=&database..&&r&i. noprint;
tables &&s&p. / missing out=&&s&p.(where=(missing(&&s&p) and percent=100));
run;
data &&s&p.;
length domain var $50;
set &&s&p.;
var="&&s&p.";
domain="&&r&i.";
keep domain var;
run;
proc append base=check data=&&s&p.;
run;
%end;
%end;
proc export data=check
outfile="&path."
dbms=xlsx replace label;
run;
%mend;
总结:
程序首先循环逻辑库下所有数据集及其所有变量,然后运用proc freq筛选某变量是否出现空值并且出现空值的百分比是否为100,如图变量a为全空即空值所占的总频数百分比为100。
再把所有符合要求变量叠加输出成数据集。
其中需要掌握dictionary的用法,sql宏变量赋值,双层嵌套循环,proc freq用法。
感谢阅读,欢迎关注, 如有疑问,欢迎后台私信,共同探讨!