- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 03-04-2009 10:51 AM
(11896 views)
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
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
4 REPLIES 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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');
if scan(species,1) in ('Genus1' 'Genus2');
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
That is what I'm after, but this code did not work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
How did it not work? DId you get an error?
Have you managed to work it the way you want?
Have you managed to work it the way you want?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Please excuse me, but It works now that I separated each 'Genus' with a comma. Problem solved! Thanks a lot for your help.