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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.