BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SASdevAnneMarie
Barite | Level 11

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.

 

Thank your for your help !

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

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").

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

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
FreelanceReinh
Jade | Level 19

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").

SASdevAnneMarie
Barite | Level 11
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'".
FreelanceReinh
Jade | Level 19

@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).

SASdevAnneMarie
Barite | Level 11
Thank you very much !

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 660 views
  • 5 likes
  • 3 in conversation