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

Hello,

 

I would like to split a character variable in SAS Viya 4 containing last names. In many cases the variable contains the last name of both partners seperated by a '-'. However, we only want the first last name. The variable looks something like this: 'xxxxxx - xxxxx'. I have tried the functions substring and getword in Viya 4, but they do not seem to do the trick. This is because many last names consist out of multiple words and both functions are not well suited for this.

 

Does someone have any idea how to tackle this in Viya? 

 

Thanks in advance.

 

Rik

1 ACCEPTED SOLUTION

Accepted Solutions
pathew
SAS Employee

In Visual Analytics you can use the FindChar / FindString functions instead, in contrast to the FindWord function you can specify the separator(s) this way. For your example this could work:

IF (FindChar(LastName, '-') > 0) return Substring(LastName, 1, FindChar(LastName, '-'))
ELSE LastName

View solution in original post

4 REPLIES 4
LinusH
Tourmaline | Level 20

SCAN function works for this kind of scenarios:

SAS Help Center: SCAN Function

Data never sleeps
Rik96
Fluorite | Level 6

I see I mentioned the wrong environment. I mean Visual Analytics. The scan function is not part of this.

pathew
SAS Employee

In Visual Analytics you can use the FindChar / FindString functions instead, in contrast to the FindWord function you can specify the separator(s) this way. For your example this could work:

IF (FindChar(LastName, '-') > 0) return Substring(LastName, 1, FindChar(LastName, '-'))
ELSE LastName
Rik96
Fluorite | Level 6

Thanks! This worked

sas-innovate-white.png

🚨 Early Bird Rate Extended!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Lock in the best rate now before the price increases on April 1.

Register now!

Tips for filtering data sources in SAS Visual Analytics

See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1079 views
  • 1 like
  • 3 in conversation