BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
lsandell
Obsidian | Level 7

Hi there! I have taxonomic data with the phyla through genus listed from microbiome 16s sequencing. I want to pull just the 'Family' name out of the string, but each character string is different due to the nature of each taxonomy identified within the sample. 

 

I have included a screenshot of the character variable "taxon" that has this string information. It's a character variable with 106 length. (I cannot share the data in full so I hope the image is enough context). Is there an approach you'd recommend taking to pull out this substring from variable starting positions? I do have a delimiter of sorts - the " / ". The most efficient method would be useful as I have over 1 million records.

 

Thank you!

 

image.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

Try this. The SCAN function is finding the second word reading from the right:

data test;
  string = 'w1/w2/w3/w4/w5/w6';
  Family = scan(string,-2,'/');
  put _all_;
run;

View solution in original post

5 REPLIES 5
sbxkoenk
SAS Super FREQ

@lsandell wrote:

I want to pull just the 'Family' name out of the string, ...


What is the 'Family' name in the strings listed?

What is the substring you need as an outcome after parsing every taxon string?

 

Koen

lsandell
Obsidian | Level 7

Just one word from the whole string (what's in between the slashes). The target string is the name before the final forward slash (/) [i.e., second to last alphabetic portion].

SASKiwi
PROC Star

So what is your business rule for identifying the family name in the string?

lsandell
Obsidian | Level 7

Thanks! It's the name before the final forward slash (/) [i.e., second to last alphabetic portion].

SASKiwi
PROC Star

Try this. The SCAN function is finding the second word reading from the right:

data test;
  string = 'w1/w2/w3/w4/w5/w6';
  Family = scan(string,-2,'/');
  put _all_;
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 346 views
  • 2 likes
  • 3 in conversation