Hello Experts,
To find 1,50% in the data string I apply the function prxmatch("/\b1,50%|\b1.750%/",line)>0.
I get a correct result for 1,50% but when I have 1.50% this function doesn't work (can't find the 1.50%). I don't know if my code is correct.
Thank you for your help.
In regular expressions period has special meaning, it will match any single character. If you want to match an actual period you need to code \. in the regular expression.
If you want to match any of a series of characters include them in a set of square brackets.
Example:
data test;
input string $char40.;
loc = prxmatch('/\b1[,\.]50%|\b1[,\.]75%/',string);
cards;
1.50%
1,50%
1.75%
1,75%
1.5%
;
Result
In regular expressions period has special meaning, it will match any single character. If you want to match an actual period you need to code \. in the regular expression.
If you want to match any of a series of characters include them in a set of square brackets.
Example:
data test;
input string $char40.;
loc = prxmatch('/\b1[,\.]50%|\b1[,\.]75%/',string);
cards;
1.50%
1,50%
1.75%
1,75%
1.5%
;
Result
@SASdevAnneMarie wrote:
Thank you, Tom!
As I understand, if I write prxmatch("/\b1.50%/",line)>0 the function is looking for 1 or 50?
No. It will be look for things like:
1.50% 1,50% 1A50% 1x50%
If you want to look for 1 or 50 you would use | just like your original post used | so it could search for 1,50% or 1.750%
Here is code that would make words that consist of only 1 or 50.
prxmatch('/\b(1|50)\b/',line)
@SASdevAnneMarie wrote:
Thank you ! If I need to get 1.50 or 1.50 % or 1.50% can I write prxmatch("/\b1[,\.]50\s*%/",line)>0 ?
s*% is right ?
Looks reasonable. Try it out. I posted a simple example data step before. So use something like that to quickly test it on a lot of different strings.
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.
Ready to level-up your skills? Choose your own adventure.