BookmarkSubscribe
Choose Language Hide Translation Bar
poulravn
Community Trekker

Equivalent to Base SAS function: scan

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

0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions
ms
Super User ms
Super User

Re: Equivalent to Base SAS function: scan

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, "_," )

View solution in original post

0 Kudos
3 REPLIES 3
ms
Super User ms
Super User

Re: Equivalent to Base SAS function: scan

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"}

0 Kudos
poulravn
Community Trekker

Re: Equivalent to Base SAS function: scan

3681_Words_test.jpg

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

Regards

Poul

0 Kudos
ms
Super User ms
Super User

Re: Equivalent to Base SAS function: scan

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, "_," )

View solution in original post

0 Kudos