BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
4 REPLIES 4
deleted_user
Not applicable
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');
deleted_user
Not applicable
That is what I'm after, but this code did not work.
deleted_user
Not applicable
How did it not work? DId you get an error?

Have you managed to work it the way you want?
deleted_user
Not applicable
Please excuse me, but It works now that I separated each 'Genus' with a comma. Problem solved! Thanks a lot for your help.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 10198 views
  • 0 likes
  • 1 in conversation