BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
BrahmanandaRao
Lapis Lazuli | Level 10

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 

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

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;

View solution in original post

1 REPLY 1
andreas_lds
Jade | Level 19

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;
How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 867 views
  • 0 likes
  • 2 in conversation