Find a value in a table

Please Help me.

User needs to input Gestational Age and Weight and the macro should find the appropriate place according to the centiles...

Don't know how to start.

Please help me!

Assuming you want to return the Percentile value for any given Weeks/Weight pair (and if you don't, please explain "find the appropriate place", and state applications involved in this)...

You first need to define your "rules" -- which aren't obvious from the table.

I assume that if a user enters

Weeks: 10
Weight: 35

...then the answer should be 50. But if they enter

Weeks: 10
Weight: 24

and

Weeks: 10
Weight: 46

...what will the answers be?

Thanks for your response

Well,

the possible answers for any given gestational age and weight would be:

-when the value matches the exact centile we return "weight is in 10th centile for the given gestational age
-or "weight is between 10th and 50th centile for the given gestational age""
-or weight is lower than 3th centile or higher than 97th centile...

These are just examples

We should be able to say if the value corresponds to a exact centile, lies between two centiles or is greater than the 97th or lower than the 3th.

Thanks for your help

OK...

So you have 6 ranges:

percentile < 3
3 <= percentile < 10
10 <= percentile < 50
50 <= percentile < 90
90 <= percentile < 97
percentile >= 97

...and you'll need answers for ranges and also special-case answers for when percentile equals the lower bound of a range.

For the "range" answers use comma-delimited text so you can access it as an array, one item per range:

percentile < 3,3 < percentile < 10,10 < percentile < 50,50 < percentile < 90,90 < percentile < 97,percentile > 97

...and similar for the "special" answers.

Set a variable to be a comma- and return-delimited version of your table, with each line being "age,weight1,weight2,weight3,weight4,weight5":

10,26,29,35,41,44
11,34,37,45,53,56
12,43,48,58,68,73
...

You can then go through the table line by line, looking for a line that starts with the age entered. You then treat that line as an array and work through it item by item (but starting with item 2, so you miss out the age value!) until weight >= item.

Test for weight = item -- if true then that's your lower bound "special case" answer so use an item from that variable, if false then you use an item from your rangesAnswers table based on the index of the matched item.

Fill out Local_table with the rest of your numbers, change the answers to suit your style, and you should be good to go:

Range from Table.kmmacros (11.3 KB)

Image

Forgive me for expressing discomfort here ...

These are quite serious calculations, and I happen to know, from experience, the real import of an obstetrician fumbling the calculation (in those days, with a kind of circular slide-rule).

I'm not at all sure that it's a good idea for a non-programmer to assemble this kind of instrument with a keyboard macro utility.

It's the kind of utility that needs very careful design and implementation and industrial grade testing.

There are many excellent applications of Keyboard Maestro.

I just don't feel that I can responsibly endorse this one.


Please don't do it.

1 Like

I think that all @Pedro.Carmo is trying to do is replace an eyeballed table lookup with dialog-response workflow based off the table already in use.

That said, I completely concur with

...and while my macro does what is asked, it certainly needs error- and sanity-checking added, and some sensible dialogs.

Thanks!

Excellent and elegant solution!

Drawing data from a web-site table ?

From manually entered numeric values ?

Keyboard Maestro's design is not type-safe – everything is a string – and this kind of application needs a proper testing framework if it is to avoid real ethical and medical risks in practical use.

From a standardised table of values -- you can see examples of the WHO tables here, complete with the usual caveats about the multiple confounding factors. I daresay most nations have something more specific to their own population(s).

Again, my feeling is that OP is replacing "person reads number from a table" with "person inputs numbers and gets number from table" -- what is then done with the number is obviously important, but only OP can answer that.