BookmarkSubscribeRSS Feed
avatar
Fluorite | Level 6

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

6 REPLIES 6
stat_sas
Ammonite | Level 13

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;

Haikuo
Onyx | Level 15

If you don't mind some Perl Regular Expression:

data want;

     set have;

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

run;

Haikuo

slchen
Lapis Lazuli | Level 10

    data want;

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

    run;

ballardw
Super User

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

avatar
Fluorite | Level 6

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

Thanks for all responses

ballardw
Super User

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 2136 views
  • 1 like
  • 5 in conversation