DATA Step, Macro, Functions and more

using INDEX to search for multiple strings

Reply
N/A
Posts: 0

using INDEX to search for multiple strings

I have a large dataset with the variable 'species' that consists of the scientific name in the form of the two word 'Genus species' and would like to assign some of these animals into a more general 'name' variable by using only the genus portion of the scientific name. I have tried to use the INDEX function but cannot figure out how to search for multiple excerpts--an example:

if index(species,'Genus1'||'Genus2') then name = 'new name';
else name = species;

this code does not generate an error but also does resolves to the 'else' statement.
INDEXC does not appear to be an option because it does not retain the character pattern.

Does anyone have any suggestions?

Thanks
N/A
Posts: 0

Re: using INDEX to search for multiple strings

Posted in reply to deleted_user
I'm not sure I totally understand what you're after but if the first word is always the genus then could you not use:

if scan(species,1) in ('Genus1' 'Genus2');
N/A
Posts: 0

Re: using INDEX to search for multiple strings

Posted in reply to deleted_user
That is what I'm after, but this code did not work.
N/A
Posts: 0

Re: using INDEX to search for multiple strings

Posted in reply to deleted_user
How did it not work? DId you get an error?

Have you managed to work it the way you want?
N/A
Posts: 0

Re: using INDEX to search for multiple strings

Posted in reply to deleted_user
Please excuse me, but It works now that I separated each 'Genus' with a comma. Problem solved! Thanks a lot for your help.
Ask a Question
Discussion stats
  • 4 replies
  • 179 views
  • 0 likes
  • 1 in conversation