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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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