From: Joe Matise on
I have to guess you have a funny character on one end or the other of the
string. 8. will probably read in the 8 digit long numbers but not the
shorter ones.

Try
acct_nbr=input(compress(account_number,,'kd'),best.);

-Joe

On Thu, Feb 18, 2010 at 9:51 AM, Tom White <tw2(a)mail.com> wrote:

> Hello SAS-L,
>
> I am strugling with converting an ACCOUNT_NUMBER variable with format and
> informat $9.
> Wjen I count the length of this variable it varies from 4 digits to 9
> digits.
> Yet, when I look at a 4-digit account_number [L=length(account_number);
> L=4]
> the actual account_number has only 3 digits. Similarly for the 9-digit. The
> actual account_number
> has only 8 digits.
>
> This leads me to believe that maybe we have a trailing zero in
> account_number.
>
> I try to conver the account_number (say, account_number=12345678 which has
> length=9 and not 8
> according to above remark).
>
> ACCT_NBR=input(account_number, best.)
>
> This doesn't convert the account numbers.
> Instead, I get . for all of them except for the last observation in the
> account_umber (wired ???)
>
> when I try
>
> ACCT_NBR=input(account_number, 9.) [The maximum lenght L=9 per note above]
> I get missing account numbers again (.) except for the last obs in
> account_number variable (wired ???)
>
> when I try
>
> ACCT_NBR=input(account_number, 8.) the accounts are converted but not all.
>
> SAS picks and chooses which ones to convert !
>
> It appears though that the 8-digit acount numbers (L=9) are being
> converted.
>
> Those account numbers with fewer than 8-digits, some are convertd, som are
> not convertd.
>
> What's going on?
>
> tom
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> =
>
From: Jim Groeneveld on
Hi Tom,

What does PROC CONTENTS say about the type and length of Account_number?
What values does the variable have, especially if not numeric?

Regards - Jim.
--
Jim Groeneveld, Netherlands
Statistician, SAS consultant
http://jim.groeneveld.eu.tf


On Thu, 18 Feb 2010 10:51:31 -0500, Tom White <tw2(a)MAIL.COM> wrote:

>Hello SAS-L,
>
>I am strugling with converting an ACCOUNT_NUMBER variable with format and
informat $9.
>Wjen I count the length of this variable it varies from 4 digits to 9 digits.
>Yet, when I look at a 4-digit account_number [L=length(account_number); L=4]
>the actual account_number has only 3 digits. Similarly for the 9-digit. The
actual account_number
>has only 8 digits.
>
>This leads me to believe that maybe we have a trailing zero in account_number.
>
>I try to conver the account_number (say, account_number=12345678 which has
length=9 and not 8
>according to above remark).
>
>ACCT_NBR=input(account_number, best.)
>
>This doesn't convert the account numbers.
>Instead, I get . for all of them except for the last observation in the
account_umber (wired ???)
>
>when I try
>
>ACCT_NBR=input(account_number, 9.) [The maximum lenght L=9 per note above]
>I get missing account numbers again (.) except for the last obs in
account_number variable (wired ???)
>
>when I try
>
>ACCT_NBR=input(account_number, 8.) the accounts are converted but not all.
>
>SAS picks and chooses which ones to convert !
>
>It appears though that the 8-digit acount numbers (L=9) are being converted.
>
>Those account numbers with fewer than 8-digits, some are convertd, som are
not convertd.
>
>What's going on?
>
>tom
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>=
From: Gerhard Hellriegel on
be careful with talking about "length". That is quite different between
char and num variables. If you deal with a char account_number with the
length 3, never define a numeric one also with length 3! I'd never use
something different than length=8 for numeric variables (default).

try

data _null_;
a_c = "1234567890";
a_n = input(a_c,20.);
put a_c=;
put a_n=;
run;

and don't use too short informats so you don't get any problems.

Gerhard




On Thu, 18 Feb 2010 10:51:31 -0500, Tom White <tw2(a)MAIL.COM> wrote:

>Hello SAS-L,
>
>I am strugling with converting an ACCOUNT_NUMBER variable with format and
informat $9.
>Wjen I count the length of this variable it varies from 4 digits to 9
digits.
>Yet, when I look at a 4-digit account_number [L=length(account_number);
L=4]
>the actual account_number has only 3 digits. Similarly for the 9-digit.
The actual account_number
>has only 8 digits.
>
>This leads me to believe that maybe we have a trailing zero in
account_number.
>
>I try to conver the account_number (say, account_number=12345678 which
has length=9 and not 8
>according to above remark).
>
>ACCT_NBR=input(account_number, best.)
>
>This doesn't convert the account numbers.
>Instead, I get . for all of them except for the last observation in the
account_umber (wired ???)
>
>when I try
>
>ACCT_NBR=input(account_number, 9.) [The maximum lenght L=9 per note above]
>I get missing account numbers again (.) except for the last obs in
account_number variable (wired ???)
>
>when I try
>
>ACCT_NBR=input(account_number, 8.) the accounts are converted but not all.
>
>SAS picks and chooses which ones to convert !
>
>It appears though that the 8-digit acount numbers (L=9) are being
converted.
>
>Those account numbers with fewer than 8-digits, some are convertd, som
are not convertd.
>
>What's going on?
>
>tom
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>=
From: Tom Abernathy on
Use the $HEX format to dump the hexcodes for the character variable.
In ASCII digits are between 30 and 39 hex. A space is 20 hex. You
most likely have either a 00 hex or a 0D (carriage return) that got
into your data somehow.

You might be able to just strip out any non-digits.

If you have latest version of SAS then use
ACCT_NBR=input(compress(account_number,,'KD'),best.);
If your version of SAS doesn't support the new modifier option on
COMPRESS then use two compress functions.

ACCT_NBR=input(compress(account_number,compress(account_number,'0123456789')),best.);

You might want to insure that you get a 1-1 mapping between the
character and numeric versions.

- Tom

On Feb 18, 10:51 am, t...(a)MAIL.COM (Tom White) wrote:
> Hello SAS-L,
>
> I am strugling with converting an ACCOUNT_NUMBER variable with format and=
>  informat $9.
> Wjen I count the length of this variable it varies from 4 digits to 9 digi=
> ts.
> Yet, when I look at a 4-digit account_number [L=3Dlength(account_number);=
>  L=3D4]
> the actual account_number has only 3 digits. Similarly for the 9-digit. Th=
> e actual account_number
> has only 8 digits.
>
> This leads me to believe that maybe we have a trailing zero in account_num=
> ber.
>
> I try to conver the account_number (say, account_number=3D12345678 which=
>  has length=3D9 and not 8
> according to above remark).
>
> ACCT_NBR=3Dinput(account_number, best.)
>
> This doesn't convert the account numbers.
> Instead, I get . for all of them except for the last observation in the ac=
> count_umber (wired ???)
>
> when I try=20
>
> ACCT_NBR=3Dinput(account_number, 9.) [The maximum lenght L=3D9 per note ab=
> ove]
> I get missing account numbers again (.) except for the last obs in account=
> _number variable (wired ???)
>
> when I try=20
> =20
> ACCT_NBR=3Dinput(account_number, 8.) the accounts are converted but not al=
> l.
>
> SAS picks and chooses which ones to convert !
>
> It appears though that the 8-digit acount numbers (L=3D9) are being conver=
> ted.
>
> Those account numbers with fewer than 8-digits, some are convertd, som are=
>  not convertd.
>
> What's going on?
>
> tom
>
> =3D

From: Nathaniel Wooding on
I agree with Gerhard about avoiding short informats. A further solution would be to simply use the Best. Informat with no length specified.


Data t;
cnum = ' 12345678';
num = input( cnum , best. );
run;


Nat Wooding

-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L(a)LISTSERV.UGA.EDU] On Behalf Of Tom White
Sent: Thursday, February 18, 2010 10:52 AM
To: SAS-L(a)LISTSERV.UGA.EDU
Subject: Convert Character into numeric

Hello SAS-L,

I am strugling with converting an ACCOUNT_NUMBER variable with format and informat $9.
Wjen I count the length of this variable it varies from 4 digits to 9 digits.
Yet, when I look at a 4-digit account_number [L=length(account_number); L=4]
the actual account_number has only 3 digits. Similarly for the 9-digit. The actual account_number
has only 8 digits.

This leads me to believe that maybe we have a trailing zero in account_number.

I try to conver the account_number (say, account_number=12345678 which has length=9 and not 8
according to above remark).

ACCT_NBR=input(account_number, best.)

This doesn't convert the account numbers.
Instead, I get . for all of them except for the last observation in the account_umber (wired ???)

when I try

ACCT_NBR=input(account_number, 9.) [The maximum lenght L=9 per note above]
I get missing account numbers again (.) except for the last obs in account_number variable (wired ???)

when I try

ACCT_NBR=input(account_number, 8.) the accounts are converted but not all.

SAS picks and chooses which ones to convert !

It appears though that the 8-digit acount numbers (L=9) are being converted.

Those account numbers with fewer than 8-digits, some are convertd, som are not convertd.

What's going on?

tom















=
CONFIDENTIALITY NOTICE: This electronic message contains
information which may be legally confidential and or privileged and
does not in any case represent a firm ENERGY COMMODITY bid or offer
relating thereto which binds the sender without an additional
express written confirmation to that effect. The information is
intended solely for the individual or entity named above and access
by anyone else is unauthorized. If you are not the intended
recipient, any disclosure, copying, distribution, or use of the
contents of this information is prohibited and may be unlawful. If
you have received this electronic transmission in error, please
reply immediately to the sender that you have received the message
in error, and delete it. Thank you.