BookmarkSubscribeSubscribe to RSS Feed
geof

Community Trekker

Joined:

May 29, 2013

Filter a string using "like" ?

Hello,

Using the example below, how could I filter all the names starting like "M"

Is it possible to use "like" or something similar ?

Data Filter( Add Filter(

        columns( :name ),

        Where( :name like M* )       /// Not working of course !

       ),

Thanks for you help

open("$sample_data\Big class.jmp");

Graph Builder(

Size( 454, 472 ),

Show Control Panel( 0 ),

Variables( X( :age ), Y( :weight ), Y( :height ), Overlay( :name ) ),

Elements( Position( 1, 1 ), Points( X, Y, Legend( 3 ), Jitter( 1 ) ) ),

Elements( Position( 1, 2 ), Points( X, Y, Legend( 4 ), Jitter( 1 ) ) )

);

1 ACCEPTED SOLUTION

Accepted Solutions
Jeff_Perkinson

Community Manager

Joined:

Jun 23, 2011

Solution

Re: Filter a string using "like" ?

Unfortunately, the Data Filter in JMP doesn't support partial string matches. You must match whole values.

However, you can find all the values that match your partial string and then use that list in your call to the data filter.

dt = open("$sample_data\Big class.jmp");

Graph Builder(

Size( 454, 472 ),

Show Control Panel( 0 ),

Variables( X( :age ), Y( :weight ), Y( :height ), Overlay( :name ) ),

Elements( Position( 1, 1 ), Points( X, Y, Legend( 3 ), Jitter( 1 ) ) ),

Elements( Position( 1, 2 ), Points( X, Y, Legend( 4 ), Jitter( 1 ) ) )

);


//create a list of the unique names

summarize(nameslist=by(:name));


//create a matrix to hold the locations of the strings that match your pattern

x=[];

//loop over list of names storing the matches in x

For( i = 1, i <= N Items( nameslist ), i++,

  If( Starts With( nameslist[i], "M" ),

// "|/" is the matrix vertical concat operator

  x = x |/ i;

  )

);

dt << Data Filter(

  Location( {848, 24} ),

  Add Filter(

  columns( :name ),

  Where( :name == nameslist[x] ),

  )

);



-Jeff
4 REPLIES
mikekutz

Community Trekker

Joined:

Sep 16, 2013

Re: Filter a string using "like" ?

I think the filter function you are looking for is:

starts with( name, "M" )

MK

sasguy

Community Member

Joined:

Jun 5, 2012

Re: Filter a string using "like" ?

Your options to mimic a like statement are as follows:

Where( starts with (:name, "M" )) /* Name starting with M */

Where( ends with (:name, "M" ))  /* Name ending with M */

Where( contains (:name, "M" ))    /* Name contains M */

Jeff_Perkinson

Community Manager

Joined:

Jun 23, 2011

Solution

Re: Filter a string using "like" ?

Unfortunately, the Data Filter in JMP doesn't support partial string matches. You must match whole values.

However, you can find all the values that match your partial string and then use that list in your call to the data filter.

dt = open("$sample_data\Big class.jmp");

Graph Builder(

Size( 454, 472 ),

Show Control Panel( 0 ),

Variables( X( :age ), Y( :weight ), Y( :height ), Overlay( :name ) ),

Elements( Position( 1, 1 ), Points( X, Y, Legend( 3 ), Jitter( 1 ) ) ),

Elements( Position( 1, 2 ), Points( X, Y, Legend( 4 ), Jitter( 1 ) ) )

);


//create a list of the unique names

summarize(nameslist=by(:name));


//create a matrix to hold the locations of the strings that match your pattern

x=[];

//loop over list of names storing the matches in x

For( i = 1, i <= N Items( nameslist ), i++,

  If( Starts With( nameslist[i], "M" ),

// "|/" is the matrix vertical concat operator

  x = x |/ i;

  )

);

dt << Data Filter(

  Location( {848, 24} ),

  Add Filter(

  columns( :name ),

  Where( :name == nameslist[x] ),

  )

);



-Jeff
geof

Community Trekker

Joined:

May 29, 2013

Re: Filter a string using "like" ?

Thanks for your help

Geof