cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
geof
Level III

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 Community Manager

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

View solution in original post

4 REPLIES 4
mikekutz
Level I

Re: Filter a string using "like" ?

I think the filter function you are looking for is:

starts with( name, "M" )

MK

sasguy
Level I

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 Community Manager

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
Level III

Re: Filter a string using "like" ?

Thanks for your help

Geof