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
- :
- 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
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Nov 29, 2014 7:21 PM
(5173 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
- 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

- Mark as New
- Bookmark
- Subscribe
- 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
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Great, thanks a lot.

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

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
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Thanks! It does not appear in the pull-down function lists. But of course when I just type "N Items(.." etc. it works.

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

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
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Yep, got it, thanks. Yeah, I had no idea that there are functions that are not in the function editor. Using JMP since ver 1, 1990-ies. Go figure.

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

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
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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.