Wednesday, July 14, 2010

Delete observations when all variabls are missing

It is a common question.

With the new function CMISS in 9.2, we can perform the task in ONLY one DATA step.
Please see the sample code at below:

data raw;
output; * obs with missing values;
a=1; b='2'; c=.;
output;
run;

data output;
set raw;
array aa {*} $ _character_;
array nn {*} _numeric_;

if cmiss(of _all_) = (dim(aa)+dim(nn)) then delete;
run;

Monday, July 5, 2010

Quick tip: %EVAL

Essentially, the value of all macro variables is character string.

Sometimes, we do need that macro variable has only numeric value.
We can use %EVAL to judge if the string is numeric value.


* Sample;
%let mv=1+a;

%let a=%eval(%scan(&mv, 1, +));
%let b=%eval(%scan(&mv, 2, +)); * Error occurs;