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 number of occurrences of specific words in ...

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

Highlighted

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

Nov 10, 2017 7:31 AM
(651 views)

Hello I'm looking to create a new column in my dataset that counts the number of times a specfic word appears in a string. The words are separated by "*" in each row.

Example table:

Animal List

1 dog*dog*cat*bird*dog

2 dog*dog*cat*bird*dog*dog

Output should be

Animal List Dog Count

1 dog*dog*cat*bird*dog 3

2 dog*dog*cat*bird*dog*dog 4

Can provide additional information if needed.

1 ACCEPTED SOLUTION

Accepted Solutions

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

Nov 10, 2017 8:27 AM
(1276 views)

Solution

Here is the formula for counting the number of times "dog" appears in a given column

`N Rows( Loc( Words( :Column 1, "*" ), "dog" ) )`

Jim

7 REPLIES

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

Nov 10, 2017 8:27 AM
(1277 views)

Here is the formula for counting the number of times "dog" appears in a given column

`N Rows( Loc( Words( :Column 1, "*" ), "dog" ) )`

Jim

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

Nov 10, 2017 10:05 AM
(631 views)

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

Nov 10, 2017 11:27 AM
(626 views)

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

Nov 10, 2017 12:02 PM
(623 views)

The following formula will find all items with the string "dog" found in it

```
wordList=words(st,"*");
count=0;for(i=1,i<=n items(wordList),i++,count=sum(count,contains(wordList[i],"dog")));
count;
```

Jim

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

2 weeks ago
(174 views)

Does the function Loc() exist only in JMP Pro?

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

txnelson wrote:Here is the formula for counting the number of times "dog" appears in a given column

`N Rows( Loc( Words( :Column 1, "*" ), "dog" ) )`

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

2 weeks ago
(172 views)

The documentation for JMP 13 does not indicate the LOC() function is only a JMP Pro function. I would validate that by running the LOC() function example in the Scripting Index

Help==>Scripting Index

```
Names Default To Here( 1 );
Show( Loc( [1 0 1 0 1 0] ) );
Show( Loc( {"A", 2, 3, 2, 5, 2, 4, [1 5]}, 2 ) );
Show(
Loc( {"A", 2, 3, 2, 5, 2, 4, [1 5]}, [1 5] )
);
```

Jim

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

2 weeks ago
(167 views)

I can confirm that the Loc() function is not specific to JMP Pro. It is available in JMP.

-Jeff