Hi guys
we can find missing values by using nmiss and cmiss functions in a dataset so how to find
missing values in all datasets and count in a library i think dictionary.tables can does
You will have to process each dataset using the cmiss (no need for nmiss, cmiss works with both types).
options dlcreatedir;
/* create some test data */
libname test "INSERT_A_DIR_NAME_HERE\test";
data test.class test.beta;
set sashelp.class;
if mod(_n_, 3) = 0 then Age = .;
if mod(_n_, 7) = 0 then Weight = .;
output test.class;
if mod(_n_, 5) = 0 then Height = .;
output test.beta;
run;
/* define the datasets holding the results */
data work.CountMiss;
length Dataset $ 42 NumMissing 8;
call missing(of _all_);
stop;
run;
/* the macro will be called by the next data step */
%macro CountMissings(Dataset=);
data _null_;
set &Dataset. end=jobDone;
NumMissing + cmiss(of _all_);
if jobDone then do;
call execute(catx(' ', 'proc sql noprint; insert into work.CountMiss'
, 'set Dataset = "&Dataset.", NumMissing =', NumMissing, ';quit;'));
end;
run;
%mend;
/* call the macro for each dataset in the library test */
data _null_;
set sashelp.vtable(keep= LibName MemName);
where LibName = 'TEST';
length Dataset $ 42;
Dataset = cats(Libname, '.', MemName);
call execute('%nrstr(%CountMissings(Dataset=' !! Dataset !! '))');
run;
/* print the results */
proc print data=work.CountMiss;
run;
You will have to process each dataset using the cmiss (no need for nmiss, cmiss works with both types).
options dlcreatedir;
/* create some test data */
libname test "INSERT_A_DIR_NAME_HERE\test";
data test.class test.beta;
set sashelp.class;
if mod(_n_, 3) = 0 then Age = .;
if mod(_n_, 7) = 0 then Weight = .;
output test.class;
if mod(_n_, 5) = 0 then Height = .;
output test.beta;
run;
/* define the datasets holding the results */
data work.CountMiss;
length Dataset $ 42 NumMissing 8;
call missing(of _all_);
stop;
run;
/* the macro will be called by the next data step */
%macro CountMissings(Dataset=);
data _null_;
set &Dataset. end=jobDone;
NumMissing + cmiss(of _all_);
if jobDone then do;
call execute(catx(' ', 'proc sql noprint; insert into work.CountMiss'
, 'set Dataset = "&Dataset.", NumMissing =', NumMissing, ';quit;'));
end;
run;
%mend;
/* call the macro for each dataset in the library test */
data _null_;
set sashelp.vtable(keep= LibName MemName);
where LibName = 'TEST';
length Dataset $ 42;
Dataset = cats(Libname, '.', MemName);
call execute('%nrstr(%CountMissings(Dataset=' !! Dataset !! '))');
run;
/* print the results */
proc print data=work.CountMiss;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.