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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 2770 views
  • 0 likes
  • 5 in conversation