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, ",");
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
To search for a specific character, use the INDEXC function. The data step language does not have a CONTAINS operator.
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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.