Barite | Level 11

## Select a right value

Hello Experts,

With prxmath function I would like to select only the values 2,25 or 2.25, 1.75 or 1,75.

So, in my code I have :  if prxmatch("m/2,25|2.25|1,75|1.75/oi",lb)>0 , but I don't know why this doesn't work, beacause I have in my selection 2.50.

1 ACCEPTED SOLUTION

Accepted Solutions

## Re: Select a right value

Hello @SASdevAnneMarie,

The issue is that the period (.) is a metacharacter that "matches any single character except newline" (see table "Other Quantifiers" in the documentation). But if you "escape" it with a backslash (see table "General Constructs"), it matches the period "." as intended. I would also suggest using the "word boundary" metacharacter \b to avoid matches of "12,25", "41.75" etc.:

`"/\b2,25|\b2\.25|\b1,75|\b1\.75/"`

But, of course, it depends on your data whether this makes sense or not (e.g., if you want to match the "2.25" in "Q2.25").

5 REPLIES 5
Diamond | Level 26

## Re: Select a right value

Explain in more detail. Show us the code. Show us a portion of the data.

By the way, you should always show us your code that doesn't work. We have asked for this  from you before. Do not make us ask repeatedly.

--
Paige Miller

## Re: Select a right value

Hello @SASdevAnneMarie,

The issue is that the period (.) is a metacharacter that "matches any single character except newline" (see table "Other Quantifiers" in the documentation). But if you "escape" it with a backslash (see table "General Constructs"), it matches the period "." as intended. I would also suggest using the "word boundary" metacharacter \b to avoid matches of "12,25", "41.75" etc.:

`"/\b2,25|\b2\.25|\b1,75|\b1\.75/"`

But, of course, it depends on your data whether this makes sense or not (e.g., if you want to match the "2.25" in "Q2.25").

Barite | Level 11

## Re: Select a right value

Thank you ! That works ! Do you know please how to add the condition and in this expression, like "/\b2,25|\b2\.25|\b1,75|\b1\.75/ and 'RATE'".

## Re: Select a right value

@SASdevAnneMarie wrote:
Do you know please how to add the condition and in this expression, like "/\b2,25|\b2\.25|\b1,75|\b1\.75/ and 'RATE'".

So you want to check if a string contains one (or more) of the numbers discussed previously and also the string "RATE" (or "'RATE'" with single quotes? Perhaps case-insensitive?)?

You could search for "RATE" with a separate function call (e.g., of the FINDW function). However, if you know positively that "RATE" would always occur before (or always after) the number, you can add it conveniently to the regular expression:

`"/\bRATE\b.*(\b2,25|\b2\.25|\b1,75|\b1\.75)/i"`

This regex matches RATE, rate, Rate, etc. (but not Strategy, rated, etc.), followed by a word boundary and a sequence of (zero or more) virtually arbitrary characters and then any of the four numbers of interest. So, example strings matching this pattern are

```Rate:1,75
The rate is exactly 2.25%.
estimated rate: 1.737 (95%-CI: 1.716-1.758)```

The latter match could be avoided by adding \b metacharacters after the numbers, but then 2.250 etc. would no longer match (without further extensions of the regex).

Barite | Level 11

## Re: Select a right value

Thank you very much !
Discussion stats
• 5 replies
• 316 views
• 5 likes
• 3 in conversation