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

Hello, I have data values that look like this for column test:

    Copper (mg/kg), DM Basis
    Total Digestible Nutrients, %, DM Basis

I need to get the string before the "(" or if it doesn't have that character, the string before the ","

 

So far I've tried this and it hasn't worked

    if test contains "(" then test1 = scan(test, 1, "(");
       else if test contains "," then test1 = scan(test, 1, ",");

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You should be able to just let SCAN() do that for you by telling it to use both ( and comma as delimiters.

test1 = scan(test, 1, "(,");

The only problem would if you want to convert

This has, comma, and (parentheses) in it.

to the longer string

This has, comma, and

instead of just

This has

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

You should be able to just let SCAN() do that for you by telling it to use both ( and comma as delimiters.

test1 = scan(test, 1, "(,");

The only problem would if you want to convert

This has, comma, and (parentheses) in it.

to the longer string

This has, comma, and

instead of just

This has

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 679 views
  • 0 likes
  • 3 in conversation