Subscribe Bookmark RSS Feed

Equivalent to Base SAS function: scan

poulravn

Community Trekker

Joined:

Jan 25, 2012

Hi, what is the JMP Script equivalent of Base SAS scan function, that splits a string according to a delimiter?

(Simple enough question, but . . . )

Regards

Poul

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

The function returns a List, which is not a data type that is supported in table cells (only numeric, character, and row state is allowed). So Words() by itself is not well adapted to column formulas.

To see the whole list as a string in the table (set column data type to "character" first):

Char( Words( :Column 1, "_," ) )

To get the first word (picks first item of list):

Words( :Column 1, "_," )[1]

or better (picks first "word" without wasting time in making a list of all "words" first):

Word( 1, :Column 1, "_," )

3 REPLIES
ms

Super User

Joined:

Jun 23, 2011

The Words() function can do that. It can handle one or more delimiters. Returns a list of all the "words".

Words( "one_two,three", "_," )

/*:

{"one", "two", "three"}

poulravn

Community Trekker

Joined:

Jan 25, 2012

3681_Words_test.jpg

Hm, then why does this not work? See attached screen dump showing formula and results in the background

Regards

Poul

Solution

The function returns a List, which is not a data type that is supported in table cells (only numeric, character, and row state is allowed). So Words() by itself is not well adapted to column formulas.

To see the whole list as a string in the table (set column data type to "character" first):

Char( Words( :Column 1, "_," ) )

To get the first word (picks first item of list):

Words( :Column 1, "_," )[1]

or better (picks first "word" without wasting time in making a list of all "words" first):

Word( 1, :Column 1, "_," )