Our World Statistics Day conversations have been a great reminder of how much statistics can inform our lives. Do you have an example of how statistics has made a difference in your life? Share your story with the Community!
Choose Language Hide Translation Bar
Highlighted
ejyoung
Level I

Searching data table for non exact matches?

I'm working on a script where I have a variable "Plate" that is set as text like "8SVPCCV1G0BB2".  I need to use this variable to select a row in a different table where "Plate" may be wildcarded like:

8S

8SV

8SQPCC

*

In this case I would want it to select the row 8SV.  But if my variable was "8PSVTTY2G0AB3" I would want it to match the * row which is a generic row.

I was looking into using regex or pattern matching for this but I'm new to both of them so I'm not having luck yet.  Am I on the right track looking at those?  Or is there a better way to do this matching?  Thanks!

2 REPLIES 2
Highlighted
ejyoung
Level I

Re: Searching data table for non exact matches?

I was able to get this to work if there is a matching line:

targetconfig << New Column ("PlateMatch", Formula(Pat Match(plate , :PlateStart)));

The only problem with this is if the plate only matches the * line.

Highlighted
ms
Super User ms
Super User

Re: Searching data table for non exact matches?

I'm sure there are several ways to approach this. One way is to first try to select the rows that match the pattern, and if no rows are selected it selects the "*" row.

// Example table

my_table = Open("$SAMPLE_DATA/Big Class.jmp");

:name[1] = "*";

// Function for selecting matching row(s)or default row "*"

select_plate = Function({dt, p},

    dt << select where(Pat Match(:name, plate));

    If(N Row(dt << getselected rows) == 0,

        dt << select where(:name == "*")

    );

);

// Test the function

plate = "ACL";

select_plate(my_table, plate);

Wait(2);

plate = "QQQ";

select_plate(my_table, plate);

Article Labels

    There are no labels assigned to this post.