Help using Base SAS procedures

numeric data with leading 0

Reply
Super Contributor
Posts: 401

numeric data with leading 0

I have imported a series of account numbers (not the real ones showing below) but imported as text.  I have some account numbers that have a leading 0 and some account numbers are different lengths .. Below are some examples.  I need to keep this account number field as numeric with the leading 0 where it should be and with the different length as required.

Example

Acct_no

12345678

01234567

123456

0123456789

So they currently import as text, but I want  them to be the way they are, however converted as numeric.

Thanks

Trusted Advisor
Posts: 3,211

Re: numeica data with leading 0

Impossilbe numeric, decimal numeric does not exist.  See also:  https://communities.sas.com/message/228508#228508. It is the digital age.  

---->-- ja karman --<-----
Super User
Posts: 10,018

Re: numeric data with leading 0

You didn't post what output you want yet .

Super Contributor
Posts: 401

Re: numeric data with leading 0

The output looking as is, but in numeric.

Acct_no

12345678

01234567

123456

0123456789

Super User
Super User
Posts: 7,039

Re: numeric data with leading 0

You seem confused on the concept of numbers versus character strings.  If you store your account ids as numbers then there is no way to distinguish between the values 123 and 0000123 since when you convert those character strings into numbers they are both one hundred and twenty three.

You can attach formats to numbers to have them displayed in different ways. So you could store 123 as a number and attached the Z7. format to it. Then when it is printed in a a report it will look like 0000123.  But the format is attached to the variable and not to just a particular value.  SAS stores data in data sets and not in a cells like a spreadsheets.  So you cannot use a different format on different observations of the data.

So you have two choices.

1) Store your account id as a character string. This is the most logical as it is NOT a number (even if people do call them account "numbers") but an identifier.  You will not be taking the mean or square root of your account ids.

2) Add another variable.  So if you wanted to treat 123 and 0000123 as different in some way you need another variable to distinguish them.  It could be the number of digits.  (123,3) vs (123,7)  It could be an actual format (123,'Z3.') vs (123,'Z7.).

Super Contributor
Posts: 401

Re: numeric data with leading 0

I think I get it.. thanks

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