%macro ndefvars(/* Creates lists of variables on a data set that never have non-missing values ("never defined vars"). This macro defines global macro vars &cvarsnd and &nvarsnd (or jst one of these as specified. */ dset, /* Data set to look at */ charvars=1, numvars=1, /* set either of these flags to 0 to ignore vars of that type */ maxobsin=99999999, /* for testing you can limit # of observations looked at */ debug=0); %global nvarsnd cvarsnd; data _null_; set &dset; %if &charvars %then %do; array _cvars (*) _character_; nc=dim(_cvars); call symput ('ncvars',put(nc,4.)); %end; %if &numvars %then %do; array _nvars (*) _numeric_; nn=dim(_nvars)-1 -&charvars; call symput ('nnvars',put(nn,4.)); %end; stop; run; %if &debug %then %put ncvars=&ncvars nnvars=&nnvars; data _null_; set &dset ( obs=&maxobsin) end=_last_; %if &charvars %then %do; %let ncvarsthisstep=%eval(&ncvars + &charvars + &numvars) ; *array _cvars (&ncvarsthisstep) _character_; array _cvars (*) _character_; array cvarcount(&ncvars) _temporary_; %end; %if &numvars %then %do; %let nnvarsthisstep=%eval(&nnvars+1); *--need to include _i (and _last_?); *array _nvars (&nnvarsthisstep) _numeric_; array _nvars(*) _numeric_; array nvarcount(&nnvars) _temporary_; %end; %if &charvars %then %do; do _i=1 to &ncvars; if _cvars(_i) ne ' ' then cvarcount(_i)=1; end; %end; %if &numvars %then %do; do _i=1 to &nnvars; if _nvars(_i) ne . then nvarcount(_i)=1; %if &debug=13 %then %do; _value=_nvars(_i); _nvarcount=nvarcount(_i); put _i= _value= _nvarcount=; %end; end; %end; if _last_ then do; length %if &charvars %then %str( _cvarlist ); %if &numvars %then %str( _nvarlist ) $32000; ; %if &charvars %then %do; do _i=1 to &ncvars; if cvarcount(_i) ne 1 then _cvarlist=trimn(_cvarlist)||' '||vname(_cvars(_i)); end; call symput('cvarsnd',trim(_cvarlist)); *--character variables never defined--; %end; %if &numvars %then %do; do _i=1 to &nnvars; if nvarcount(_i) ne 1 then _nvarlist=trimn(_nvarlist)||' '||vname(_nvars(_i)); %if &debug=13 %then %do; _vname=vname(_nvars(_i)); _nvarcount=nvarcount(_i); put _i= _vname= _nvarcount=; %end; end; call symput('nvarsnd',trim(_nvarlist)); *--numeric variables never defined-; %end; put / _all_; end; run; %mend ndefvars;