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

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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 310 views
  • 0 likes
  • 3 in conversation