DATA Step, Macro, Functions and more

Delete obsvations with certain strings

Reply
Frequent Contributor
Posts: 76

Delete obsvations with certain strings

Hi all,

 

Say I have the following observations:

fruit

apple

apple comments

pear

pear comment

banan

 

I want to delete those have 'comments' and 'comment'.

 

I wrote code as

 

data mock; set mock0; run;
data mock;
modify mock;
where fruit contains 'comment' and 'comments';
remove;
run;

 

But it doesn't remove those with 'comments'. Can I do thses two select at once?

 

Thanks alot!

 

 

Super User
Posts: 11,338

Re: Delete obsvations with certain strings

Posted in reply to Xiaoningdemao

where fruit contains 'comment' or fruit contains 'comments';

Respected Advisor
Posts: 4,919

Re: Delete obsvations with certain strings

Posted in reply to Xiaoningdemao

If you are going to create a new dataset anyway, you might as well filter as you copy:

 

data mock;
set mock0;
where not (fruit contains "comment" or fruit contains "comments");
run; 
PG
Super User
Super User
Posts: 7,942

Re: Delete obsvations with certain strings

Would:

data mock;
  set mock0;
  where index(fruit,"comment")=0;
run;

Not be simpler?

Ask a Question
Discussion stats
  • 3 replies
  • 185 views
  • 1 like
  • 4 in conversation