Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SAS PROC SQL - How to convert string to number

Tags:

sas

proc-sql

I want to convert a string to number in a SAS SQL PROC. The oracle-sql functioncs as TO_NUMBER() or INT() do not work. I also tried the CAST(<my string> AS <target type>) function but it does not recognize the target type INT or INTEGER.

like image 602
paolof89 Avatar asked Nov 02 '25 16:11

paolof89


1 Answers

Probably the best way would be to use:

input(your_string_variable, best.) as your_new_numeric_variable

You need to replace your_string_variable and your_new_numeric_variable appropriately. Best. is SAS format ("informat", to be exact) that tries to read in as many reasonable numeric formats as possible, it will work in majority of cases whether representation of a number you have. Still it makes sense to review the results or find a more specific format if you're interested in controlling the input.

like image 156
uzbad Avatar answered Nov 04 '25 10:11

uzbad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!