Drop is a declarative statement that can't be executed conditionally, as it is meant to alter the data structure.
If you want to get rid of observattons with faulty entries, use a where condition, a subsetting if, or a conditional delete:
/* method with where */
date have;
set want;
where lengthn(cpr) ge 10;
run;
/* subsetting if */
date have;
set want;
if lengthn(cpr) ge 10;
run;
/* delete */
date have;
set want;
if lengthn(cpr) < 10 then delete;
run;
Drop is a declarative statement that can't be executed conditionally, as it is meant to alter the data structure.
If you want to get rid of observattons with faulty entries, use a where condition, a subsetting if, or a conditional delete:
/* method with where */
date have;
set want;
where lengthn(cpr) ge 10;
run;
/* subsetting if */
date have;
set want;
if lengthn(cpr) ge 10;
run;
/* delete */
date have;
set want;
if lengthn(cpr) < 10 then delete;
run;
In real life, data mistakes come in all shapes and sizes.
There might be leading blanks.
There might be letters mixed in with the numbers.
There might be values that are longer than 10 characters.
If you want to keep observations that have exactly 10 digits, consider:
if length(compress(cpr, , 'kd') ) = 10;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Registration is open
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss. Register now and lock in 2025 pricing—just $495!