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 !
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").
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.
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 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).
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: