BookmarkSubscribeRSS Feed
01SASUser
Fluorite | Level 6

I use the INPUT function in order for me to convert character to numeric variable:

Ex:

(INPUT(txt_to_numeric,23.)) as txt_to_numeric length = 8

However, I am having an issue converting it to numeric. If the character variable is enclosed in parenthesis, in accounting term this is a negative value, the input function does not read it as a negative value but rather it reads it as NULL.

May I know how to revise my code such that if the character value is (5) for example, it will convert it to numeric value as -5? Thanks.

4 REPLIES 4
jakarman
Barite | Level 11

The IBAN (International Bank Account Number - Wikipedia, the free encyclopedia) is a number?  Come on, it is containing LETTERS.

Numbers in SAS are float https://support.sas.com/techsup/technote/ts654.pdf keep them on length 8 as it is the default and standard Double-precision floating-point format - Wikipedia, the free encyclopedia implemented by Intel and other chip-baking processors (CPU).

When you are happy with a precision of meaningfull 12 digits (not those 23) you can use it. Needing more precision you could investigate proc ds2.

Reading numeric goes by informats, there are a lot of them including commax. SAS(R) 9.4 Formats and Informats: Reference  (reading those () ) 

When there as a dedicated format needed you can create that using proc format / fcmp  

---->-- ja karman --<-----
Kurt_Bremser
Super User

Don't know out of my head if there is an informat for this. You may have to do the conversion manually. Replace the leading "(" with "-", omit the trailing ")".

Vladislaff
SAS Employee

You can try the comma. informat.

(INPUT(txt_to_numeric,COMMA23.)) as txt_to_numeric length = 8

Ksharp
Super User

Use another informat:

data have;
input x percent.;
cards;
5
(5)
4
9
;
run;


Xia Keshan

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register 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
  • 4 replies
  • 2987 views
  • 0 likes
  • 5 in conversation