Try this. %macro missing_rpt(data=); proc contents data=&data noprint out=_contents; run; data _null_; set _contents end=last; call symput(cats('var',_n_),strip(name)); call symput(cats('type',_n_),strip(type)); if last then do; call symput('nvars',strip(_n_)); end; run; %let delim=; proc sql; create table _missing_counts as select %do i=1 %to &nvars; %if &i>1 %then %let delim=%str(,); %if &&type&i=1 %then %do; &delim.sum(case when &&var&i=. then 1 else 0 end) as &&var&i %end; %else %do; &delim.sum(case when &&var&i='' then 1 else 0 end) as &&var&i %end; %end; from &data ;quit; proc transpose data=_missing_counts out=_missing_counts_t; run; proc sql; select _name_ label='Variable', col1 label='Missing Value Count' from _missing_counts_t order by _name_ ;quit; %mend; %missing_rpt(data=mylib.mydata);
... View more