I would like to convert variable 'res' into numeric. But I would like to do it for the records that only have digit value ( in our case it is 12.3 ). So I used a perl regular expression. But I have tried write an expression so that the returned value of prxmatch is equal to 0 for 12.3 and non zero for other cases. It doesn work...Any clue ?
Cheers
SasKap
data test;
input res $20.;
p=prxparse("/\<\>\+\D/");
pos=prxmatch(p,res);
put var= p= pos=;
cards;
12.3
<5
>9
+5
unknown
;
run;
Why is +5 not a number? I would do:
data test;
if not p then p + prxparse("/^[+-]?\d+\.?\d*/");
input res $20.;
pos=prxmatch(p,res);
put res= pos=;
cards;
12.3
<5
>9
+5
unknown
-123
;
Why is +5 not a number? I would do:
data test;
if not p then p + prxparse("/^[+-]?\d+\.?\d*/");
input res $20.;
pos=prxmatch(p,res);
put res= pos=;
cards;
12.3
<5
>9
+5
unknown
-123
;
What would you like for your final output for that example? I'm not sure how you are going to use the 0 result.
Why not use ?? operator ?
data test;
input res $20.;
pos=input(res,?? best32.);
* input res ?? best32. ;
put res= pos=;
cards;
12.3
<5
>9
+5
unknown
-123
;
run;
The ?? suppresses error messages when reading non-numeric values and does not set the automatic _ERROR_ variable to 1.
Someone has already answer your question. But I think the best way to understand it is to check SAS documnetation.
y=input(x, ?? best.);
<==>
y=input(x, ? best.);
_error_=1;
Thanks. I have checked first the help documentation before raising the question but I could not find any answer. The only answer when typing '?' in the index search from help doc , was about greplay procedure....Nothing as well with google..
Cheers
Saskap
You would find the answer under INPUT function in the documentation.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.