LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (February 2010, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 18 Feb 2010 12:57:38 -0500
Reply-To:   tw2@MAIL.COM
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Tom White <tw2@MAIL.COM>
Subject:   Re: Convert Character into numeric
Comments:   To: snoopy369@GMAIL.COM
In-Reply-To:   <b7a7fa631002180936t3a242610lc1bd96f3c17a509f@mail.gmail.com>
Content-Type:   text/plain; charset="us-ascii"

Thank you all for your inputs:

joe jim gerhard nat

tom

-----Original Message----- From: Joe Matise <snoopy369@GMAIL.COM> To: SAS-L@LISTSERV.UGA.EDU Sent: Thu, Feb 18, 2010 11:36 am Subject: Re: Convert Character into numeric

BEST. is really BEST12., if I remember correctly. -Joe On Thu, Feb 18, 2010 at 11:33 AM, Gerhard Hellriegel < erhard.hellriegel@t-online.de> wrote: > seems that there is a default for best. I get the following with very long numbers:

23 data _null_; 24 a_c = "12345678953535350"; 25 a_n = input(a_c,best.); 26 put a_c=; 27 put a_n=; 28 run;

a_c=12345678953535350 a_n=123456789535

anyway tehre is no good way to use very long numbers as keys, e.g as a accounting number:

data _null_; a_c = "1234567890123456789"; a_n = input(a_c,32.); put a_c; put a_n 19.; run;

the result is:

1234567890123456789 1234567890123456768

That is simply a problem of the number of significant digits in a 8-byte numeric variable. It is too long! If it is necessary to have longer account_numbers, you must use a character variable for that. In that case it might be also a better way to make it shorter and use a, b, c, ... for making it unique. Or you start with numerics (it's easier to generate a unique key by simply adding 1....) and hope that until you reach the limit there is a SI- solution for the "short" numbers, e.g. a 16- or 32-byte representation of numbers. Think 16 byte would be very much, 1 byte for exponent, 15*8-1 bit for the number = 2**120-1 as biggest number ... SAS says that this is something around 1.3e36 so I think 35 digits should be reliable then. Ok, to be more sure, perhaps 32 byte, 2 for exponent, 30 for mantissa (30*8-1 means 1.7e72, so 70 digits should be ok, enough for the next few years to contain the national dept of Germany - not sure about that...)

Gerhard

On Thu, 18 Feb 2010 12:03:19 -0500, Nathaniel Wooding <nathaniel.wooding@DOM.COM> wrote:

>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@LISTSERV.UGA.EDU] On Behalf Of Tom White >Sent: Thursday, February 18, 2010 10:52 AM >To: SAS-L@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.

-----Original Message----- From: Joe Matise <snoopy369@GMAIL.COM> To: SAS-L@LISTSERV.UGA.EDU Sent: Thu, Feb 18, 2010 11:36 am Subject: Re: Convert Character into numeric

BEST. is really BEST12., if I remember correctly. -Joe On Thu, Feb 18, 2010 at 11:33 AM, Gerhard Hellriegel < erhard.hellriegel@t-online.de> wrote: > seems that there is a default for best. I get the following with very long numbers:

23 data _null_; 24 a_c = "12345678953535350"; 25 a_n = input(a_c,best.); 26 put a_c=; 27 put a_n=; 28 run;

a_c=12345678953535350 a_n=123456789535

anyway tehre is no good way to use very long numbers as keys, e.g as a accounting number:

data _null_; a_c = "1234567890123456789"; a_n = input(a_c,32.); put a_c; put a_n 19.; run;

the result is:

1234567890123456789 1234567890123456768

That is simply a problem of the number of significant digits in a 8-byte numeric variable. It is too long! If it is necessary to have longer account_numbers, you must use a character variable for that. In that case it might be also a better way to make it shorter and use a, b, c, ... for making it unique. Or you start with numerics (it's easier to generate a unique key by simply adding 1....) and hope that until you reach the limit there is a SI- solution for the "short" numbers, e.g. a 16- or 32-byte representation of numbers. Think 16 byte would be very much, 1 byte for exponent, 15*8-1 bit for the number = 2**120-1 as biggest number ... SAS says that this is something around 1.3e36 so I think 35 digits should be reliable then. Ok, to be more sure, perhaps 32 byte, 2 for exponent, 30 for mantissa (30*8-1 means 1.7e72, so 70 digits should be ok, enough for the next few years to contain the national dept of Germany - not sure about that...)

Gerhard

On Thu, 18 Feb 2010 12:03:19 -0500, Nathaniel Wooding <nathaniel.wooding@DOM.COM> wrote:

>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@LISTSERV.UGA.EDU] On Behalf Of Tom White >Sent: Thursday, February 18, 2010 10:52 AM >To: SAS-L@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.


Back to: Top of message | Previous page | Main SAS-L page