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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 2504 views
  • 0 likes
  • 5 in conversation