Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Count the number of words in a string?

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Nov 29, 2014 7:21 PM
(8749 views)

Can someone tell me the best function to count the number of a words in a particular string? For example, if I have a column of character data delimited by ";" or "," how do I count the number of "words" in that column, as defined by the particular delimiter? I know SAS has a function COUNTW that does this, but I can't find anything in JMP that will do it. Thanks in advance...

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

It takes two functions in JMP. The *Words()* function returns a list of the words in a string and *N Items()* gives the number of items in a list.

N Items( Words( s, ";,"))

9 REPLIES 9

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

It takes two functions in JMP. The *Words()* function returns a list of the words in a string and *N Items()* gives the number of items in a list.

N Items( Words( s, ";,"))

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Count the number of words in a string?

Great, thanks a lot.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Count the number of words in a string?

Does the function N Items exist only in JMP Pro?

Is there a way to count words or specific symbols in a string in regular JMP?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Count the number of words in a string?

N Items() is a function that has been a part of JMP for a long time. Check in the Scripting Index of your version of JMP to make sure it is there. I assume it will be. It is an essential component of being able to deal with JMP Lists.

Here is one way to count words and to count symbols

Names Default To Here( 1 );

str1 = "This is a test of the counting of words";

str2 = "Here is* a way to* count * symbols";

Show( "Counting Words", N Items( Words( str1, " " ) ) );

Show( "Counting Symbols", N Items( Words( str2, "*" ) ) );

Jim

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Count the number of words in a string?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Count the number of words in a string?

I assume the pulldown menu you are referring to is in the Formula Editor. That list is not the definative list of functions. It contains those functions that "Typically" are used in a formula calculation. The definative documentation is in the Scripting Index

Help==>Scripting Index

Jim

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Count the number of words in a string?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Count the number of words in a string?

Minor point - your symbol count could be off by 1 if the last character is not the symbol. In Jim's example the result is 4 when there are actually only 3 symbols. Here's one way to get the correct number of symbols:

```
str2 = "Here is* a way to* count * symbols";
str3 = substitute(str2, "*", "");
nsymbols = length(str2) - length(str3);
```

I'm curious if there's an easier way to do this?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Count the number of words in a string?

this method did occur to me, but it was not erfect for my goal of counting words in a string with words separated by a variety of delimiters, would have had to do this several time for each delimiter.

N Items(Words(string, " ,;|:_")) works great.