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;
Ready to join fellow brilliant minds for the SAS Hackathon?
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.