DATA Step, Macro, Functions and more

how can I find these values are numeric from a char variable

Reply
Super Contributor
Posts: 345

how can I find these values are numeric from a char variable


 if  substr(icd, 1,3) in ( '0', '1', '2', '3', '4', '5', '6', '7', '8', '9') then num ="Y";else num ="N";

my code does not work

 

any ideas on how to modify?

Thanks

Super Contributor
Posts: 279

Re: how can I find these values are numeric from a char variable

Have you run PROC CONTENTS?  

PROC Star
Posts: 1,322

Re: how can I find these values are numeric from a char variable

I haven't used it, but perhaps NOTDIGT() is a possibility:

 

184  data _null_;
185    input text $;
186    if notdigit(trim(text))=0 then num="Y";
187    else num="N";
188    put (text num)(=);
189    cards;

text=hello num=N
text=123 num=Y
text=1 num=Y
text=4,321 num=N
text=1.5 num=N
text=m1m num=N

196  ;
197  run;

 

 

I think that should work, nof by numeric you mean contains only numbers.  As shown above, characters such as comma or decimal point are considered non-numeric.

 

Kind Regards,

--Q.

Super User
Posts: 5,513

Re: how can I find these values are numeric from a char variable

Clearly, this code will rarely work.  It examines the first three characters in your variable to specifically see if the first character is a digit and the second and third characters are both blanks.  I doubt that is what you wanted to accomplish.

 

What did you want to accomplish?  You will have to explain it in words, rather than show code that doesn't work.

Super Contributor
Posts: 345

Re: how can I find these values are numeric from a char variable

Posted in reply to Astounding

you are right, i found this problem and fixed it thanks

Ask a Question
Discussion stats
  • 4 replies
  • 238 views
  • 0 likes
  • 4 in conversation