Desktop productivity for business analysts and programmers

find function

Reply
Contributor
Posts: 66

find function

Hi,

I am interested to delete some drugs in a string (occuring in the middle of the string that has drug name) . I used find function like below. it works however  I have a long list of

if find (therapy, 'ACTEMRA') then delete;

if find (therapy, 'AVASTIN') then delete;

if find (therapy, 'AVEED') then delete;

if find (therapy, 'BOTOX') then delete;

if find (therapy, 'DACOGEN') then delete;

Is it possible to combine all and more drugs in one statement?

Please advise.

Thanks

Trusted Advisor
Posts: 1,228

Re: find function

Something like this may help.

data want;

     set have;

  array del(5) ACTEMRA AVASTIN AVEED BOTOX DACOGEN;

  counter=0

     do i=1 to dim(del);

           if find(therapy,vname(del(i)), 'i') then counter+1;

     end;

  if counter>=1 then delete;

run;

Respected Advisor
Posts: 3,156

Re: find function

If you don't mind some Perl Regular Expression:

data want;

     set have;

     if not prxmatch('/(ACTEMRA|AVASTIN|AVEED|BOTOX|DACOGEN)/', var);

run;

Haikuo

Super Contributor
Posts: 275

Re: find function

    data want;

    set have(where=(therapy not in ('ACTEMRA' 'AVASTIN' 'AVEED' 'BOTOX' 'DACOGEN')));

    run;

Super User
Posts: 11,114

Re: find function

The IN will not work if the variable value actually is "AVASTIN 10MG" or similar additional information.

Contributor
Posts: 66

Re: find function

That is exactly the problem
I guess I may have to stick with Find function.

Thanks for all responses

Super User
Posts: 11,114

Re: find function

A modification of

data want;

     set have;

  array del{5} $ _temporary_  ('ACTEMRA','AVASTIN','AVEED','BOTOX','DACOGEN'); /* add the values and update the number in the array reference

  counter=0;

     do i=1 to dim(del);

           if find(therapy,del(i)) then counter+1;

     end;

  if counter>=1 then delete;

  drop i counter;

run;

Ask a Question
Discussion stats
  • 6 replies
  • 492 views
  • 1 like
  • 5 in conversation