BookmarkSubscribeRSS Feed
SASdevAnneMarie
Rhodochrosite | Level 12

Hello Experts,

 

Today, I'm using the following code to extract rates. I'm wondering if I can create a macro using PRXMATCH to check the values,  from 0.50% to 2.70% ?

 

if (prxmatch("/\b0[,\.]45\s*%/",lb_lg)>0
or prxmatch("/\b0[,\.]45\s*%/",lb_)>0)
or (prxmatch("/\b0[,\.]45\s*%/",lb_lg)>0
or prxmatch("/\b0[,\.]45\s*%/",lb)>0) then
do;
Taux=0.0045;
end;

if (prxmatch("/\b0[,\.]50\s*%/",lb_lg)>0
or prxmatch("/\b0[,\.]50\s*%/",lb)>0)
or (prxmatch("/\b0[,\.]5\s*%/",lb_lg)>0
or prxmatch("/\b0[,\.]5\s*%/",lb)>0) then
do;
Taux=0.005;
end;

if prxmatch("/\b1(\.0\b|\.0\%|\%|\s)/",lb_lg)>0 
or prxmatch("/\b1(\.0\b|\.0\%|\%|\s)/",lb)>0 then
do;
Taux=0.01;
end;

Thank you !

6 REPLIES 6
PaigeMiller
Diamond | Level 26

I think far easier is to convert the text which you describe as 0.50% to 2.70% to actual numbers and then checking becomes much much much much easier. And then likely no macro is needed.

--
Paige Miller
SASdevAnneMarie
Rhodochrosite | Level 12

Thank you, Paige Miller, but I didn't fully understand your idea.

Tom
Super User Tom
Super User

Use the INPUT() function to convert the string into the number it represents and then it will be much easier to compare.

 

For more help show some examples of the input strings you need to test.

SASdevAnneMarie
Rhodochrosite | Level 12
Thank you, Tom.
I'm wondering if I can do this with "prxmatch" :
%macro mymacro(var);
if (prxmatch("/\b0[,\.]&VAR.\s*%/",lb_lg)>0 then ....
%mend;
%mymacro(var=50);
PaigeMiller
Diamond | Level 26

@SASdevAnneMarie wrote:
Thank you, Tom.
I'm wondering if I can do this with "prxmatch" :
%macro mymacro(var);
if (prxmatch("/\b0[,\.]&VAR.\s*%/",lb_lg)>0 then ....
%mend;
%mymacro(var=50);

Your are wondering if you can do this with prxmatch. The answer is for you to try it. 


it is impossible for me to advise you further since I don't know what you are trying to do. Would you please explain what you are trying to do? Please explain in words without reference to PRXMATCH or any other code.

 

--
Paige Miller
PaigeMiller
Diamond | Level 26

@SASdevAnneMarie wrote:

Thank you, Paige Miller, but I didn't fully understand your idea.


The whole idea is that numbers are easier to handle as numbers than if you leave them as text. If there was something I could advise less experienced people to do, it would be to ALWAYS convert text strings which are really numbers to actual numbers. 

--
Paige Miller

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand in the Innovate Hub.

Watch Now →
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
  • 6 replies
  • 295 views
  • 5 likes
  • 3 in conversation