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

October 13, 2011
By

This post was kindly contributed by StudySAS Blog - go there to comment and to read the full post.


/* 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 create */

/* a separate output data set */

proc freq…

[[ This is a content summary only. Visit my website for full links, other content, and more! ]]

This post was kindly contributed by StudySAS Blog - go there to comment and to read the full post.

Tags: ,

Welcome!

SAS-X.com offers news and tutorials about the various SAS® software packages, contributed by bloggers. You are welcome to subscribe to e-mail updates, or add your SAS-blog to the site.

Sponsors







Dear readers, proc-x is looking for sponsors who would be willing to support the site in exchange for banner ads in the right sidebar of the site. If you are interested, please e-mail me at: tal.galili@gmail.com
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration.