DATA Step, Macro, Functions and more

Conversion from Character to Numeric (Accounting Numbers)

Reply
Contributor
Posts: 22

Conversion from Character to Numeric (Accounting Numbers)

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.

Trusted Advisor
Posts: 3,211

Re: Conversion from Character to Numeric (Accounting Numbers)

Posted in reply to 01SASUser

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 --<-----
Super User
Posts: 7,758

Re: Conversion from Character to Numeric (Accounting Numbers)

Posted in reply to 01SASUser

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 ")".

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
SAS Employee
Posts: 15

Re: Conversion from Character to Numeric (Accounting Numbers)

Posted in reply to 01SASUser

You can try the comma. informat.

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

Super User
Posts: 10,018

Re: Conversion from Character to Numeric (Accounting Numbers)

Posted in reply to 01SASUser

Use another informat:

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


Xia Keshan

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