Posts

Showing posts with the label detect the missing values. non missing

Counting the number of missing and non-missing values for each variable in a data set.

/* create sample data */ data one; input a $ b $ c $ d e; cards; a . a 1 3 . b . 2 4 a a a . 5 . . b 3 5 a a a . 6 a a a . 7 a a a 2 8 ; run; /* create a format to group missing and non-missing */ proc format; value $missfmt ' '=' missing ' other='non-missing'; value missfmt .=' missing ' other= 'non-missing' ; run; %macro lst(dsn); /** open dataset **/ %let dsid= %sysfunc (open(&dsn)); /** cnt will contain the number of variables in the dataset passed in **/ %let cnt= %sysfunc (attrn(&dsid,nvars)); %do i = 1 %to &cnt; /** create a different macro variable for each variable in dataset **/ %let x&i= %sysfunc (varname(&dsid,&i)); /** list the type of the current variable **/ %let typ&i= %sysfunc (vartype(&dsid,&i)); %end; /** close dataset **/ %let rc= %sysfunc ( close (&dsid)); %do i = 1 %to &cnt; /* loop through each variable in PROC FREQ and ...