Prev: Convert Character into numeric
Next: Date Format issue
From: "Keintz, H. Mark" on 18 Feb 2010 16:44 Gerhard said below "I'd never use something different than length=8 for numeric variables". Never? Really? I often shorten storage length of numeric variables. For instance one of our datasets has over 4,000,000,000 observations for each month of trading activity on the New York Stock Exchange. One of the variables is the DATE of the price quote. I shorten the storage length of DATE to length 4. Since SAS date formats and functions only use the integer portion of the date value, and since the largest consecutive integer that this length will hold on our UNIX system is 2,097,152 (Oct 23, 7701), there is no risk of loss of precision for our researchers. The disk savings is 16GBytes. Now the PRICE variable, which is in units of dollars, but recorded to a precision of cents, (e.g. 121.56) we leave at full precision (length 8). In other words, when there is significant space to be saved, we take what the dataset will give us via the LENGTH statement. Regards, Mark -----Original Message----- From: SAS(r) Discussion [mailto:SAS-L(a)LISTSERV.UGA.EDU] On Behalf Of Gerhard Hellriegel Sent: Thursday, February 18, 2010 11:50 AM To: SAS-L(a)LISTSERV.UGA.EDU Subject: Re: Convert Character into numeric 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: xlr82sas on 18 Feb 2010 17:35 On Feb 18, 10:12 am, diannerho...(a)COMCAST.NET (Dianne Rhodes) wrote: > On Thu, 18 Feb 2010 11:36:37 -0600, Joe Matise <snoopy...(a)GMAIL.COM> wrote: > >BEST. is really BEST12., if I remember correctly. > > >-Joe > > Yeah, the default for BEST is BEST12. I would avoid using it as it can > produce "unexpected" results. > > Dianne @ census Hi SAS-Lers, It looks to me like 20. is a safer default input format then best. (which is just best12.) best. and 20. do NOT give same results X1=12345678901234567890 BEST=123456789012.0000000 W20=12345678901234567168 best. and 20. give the SAME reults X2=1E150 BEST=1E150 W20=1E150 best. and 20. do NOT give same results X3=.000000000000001 BEST=0.000000000000000 W20=0.000000000000001 best. and 20. do NOT give same results X4=1234567890123 BEST=123456789012.0000000 W20=1234567890123.000000 best. and 20. do NOT give same results X5=1.7976931348623E308 BEST=1.797693134000000 W20=1.7976931348623E308 best. and 20. give the SAME reults X6=0.000000000000000 BEST=0.000000000000000 W20=0.000000000000000 best. and 20. do NOT give same results X7=3.141592653589790 BEST=3.141592600000000 W20=3.141592653589790 best. and 20. do NOT give same results X8=1234567890.999 BEST=1234567890.900000000 W20=1234567890.999000000 %macro utl_eqfuzz(var1, var2, fuzz=1e-15); . < abs(&var1 - &var2) < &fuzz %mend utl_eqfuzz; data tst; format y: best W20 20.15; x1='12345678901234567890'; x2='1E150'; x3='.000000000000001'; x4='1234567890123'; x5=put(constant('big'),20.15); x6=put(constant('small'),20.15); x7=put(constant('pi'),20.15); x8='1234567890.999'; y1=12345678901234567890; y2=1E150; y3=.000000000000001; y4=1234567890123; y5=constant('big'); y6=constant('small'); y7=constant('pi'); y8=1234567890.999; array num[*] x:; array res[*] y:; do idx=1 to dim(num); /* best. and best. are the same */ best=input(num[idx],best.); W20=input(num[idx],20.); if %utl_eqfuzz(best,W20) then put "best. and 20. give the SAME reults " / num[idx]= / best= / W20= ; else put "best. and 20. do NOT give same results " / num[idx]= / best= / W20= ; put ///; end; run;
From: Nathaniel Wooding on 19 Feb 2010 07:36 Gerhard I missed the bit about the embedded hex character and I, took would probably look to see just what was there. That was one of the nice features of the ISPF editor -- you could do a picture search that would find a non-printing character and then switch to hex mode so that you could identify it. Nat -----Original Message----- From: SAS(r) Discussion [mailto:SAS-L(a)LISTSERV.UGA.EDU] On Behalf Of Joe Matise Sent: Thursday, February 18, 2010 12:27 PM To: SAS-L(a)LISTSERV.UGA.EDU Subject: Re: Convert Character into numeric The OP tried that already. I suspect he has a nonprinting character in there somewhere; COMPRESS removes that, and he confirmed offline that solution worked. Of course if one is curious what those characters are, could always use the $HEX. informat to see what they are, right? -Joe On Thu, Feb 18, 2010 at 11:03 AM, Nathaniel Wooding < nathaniel.wooding(a)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(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. >
From: xlr82sas on 19 Feb 2010 11:51 On Feb 19, 4:36 am, nathaniel.wood...(a)DOM.COM (Nathaniel Wooding) wrote: > Gerhard > > I missed the bit about the embedded hex character and I, took would probably look to see just what was there. That was one of the nice features of the ISPF editor -- you could do a picture search that would find a non-printing character and then switch to hex mode so that you could identify it. > > Nat > > > > -----Original Message----- > From: SAS(r) Discussion [mailto:SA...(a)LISTSERV.UGA.EDU] On Behalf Of Joe Matise > Sent: Thursday, February 18, 2010 12:27 PM > To: SA...(a)LISTSERV.UGA.EDU > Subject: Re: Convert Character into numeric > > The OP tried that already. I suspect he has a nonprinting character in > there somewhere; COMPRESS removes that, and he confirmed offline that > solution worked. > > Of course if one is curious what those characters are, could always use the > $HEX. informat to see what they are, right? > > -Joe > > On Thu, Feb 18, 2010 at 11:03 AM, Nathaniel Wooding < > nathaniel.wood...(a)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:SA...(a)LISTSERV.UGA.EDU] On Behalf Of Tom > > White > > Sent: Thursday, February 18, 2010 10:52 AM > > To: SA...(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.- Hide quoted text - > > - Show quoted text - Hi SAS-Lers, I also used the picture search and hex on capabilities available back in the 80s. I also believe SAS allowed users to easily integrate other editors directly into the early display manager. I also miss X, XX and ISPF panels. I use FSLIST to interactively view a file in hex. Note if you use the old editor and turn the command line on then many useful 'old' procedures seem to come alive(FSEDIT/FSVIEW....). It really upsets me thet the command line does not work in viewtatble, it does work in the old FS procs, you can even have different function settings in the old procs. All this goes away with EG. You can find more on displaying hex using SAS on my site http://homepage.mac.com/magdelina/.Public/utl.html utl_tipweb.txt /* T000380 VIEWING A FILE IN HEXIDECIMAL IN UNIX AND WINDOWS SAS (3 Methods)
From: Nathaniel Wooding on 19 Feb 2010 20:03
I received the code below from Koen Vyverman who was active on SASL prior to his joining SAS Institute. For a while, he posted using the name Killovolt. Anyway, the goal of the first statement is to translate punctuation into blanks. The second translates non-printing hex strings into spaces and compress them out. paragraph=left(compbl(translate(_infile_,' ',';:",.?!()<>[]{}*^@~#$%_+=`'))); paragraph=left(compbl(translate(paragraph,' ','000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F'x))); There are some new 9.2 compress options that may make this obsolete. Nat Wooding -----Original Message----- From: SAS(r) Discussion [mailto:SAS-L(a)LISTSERV.UGA.EDU] On Behalf Of xlr82sas Sent: Friday, February 19, 2010 11:51 AM To: SAS-L(a)LISTSERV.UGA.EDU Subject: Re: Convert Character into numeric On Feb 19, 4:36 am, nathaniel.wood...(a)DOM.COM (Nathaniel Wooding) wrote: > Gerhard > > I missed the bit about the embedded hex character and I, took would probably look to see just what was there. That was one of the nice features of the ISPF editor -- you could do a picture search that would find a non-printing character and then switch to hex mode so that you could identify it. > > Nat > > > > -----Original Message----- > From: SAS(r) Discussion [mailto:SA...(a)LISTSERV.UGA.EDU] On Behalf Of Joe Matise > Sent: Thursday, February 18, 2010 12:27 PM > To: SA...(a)LISTSERV.UGA.EDU > Subject: Re: Convert Character into numeric > > The OP tried that already. I suspect he has a nonprinting character in > there somewhere; COMPRESS removes that, and he confirmed offline that > solution worked. > > Of course if one is curious what those characters are, could always use the > $HEX. informat to see what they are, right? > > -Joe > > On Thu, Feb 18, 2010 at 11:03 AM, Nathaniel Wooding < > nathaniel.wood...(a)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:SA...(a)LISTSERV.UGA.EDU] On Behalf Of Tom > > White > > Sent: Thursday, February 18, 2010 10:52 AM > > To: SA...(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.- Hide quoted text - > > - Show quoted text - Hi SAS-Lers, I also used the picture search and hex on capabilities available back in the 80s. I also believe SAS allowed users to easily integrate other editors directly into the early display manager. I also miss X, XX and ISPF panels. I use FSLIST to interactively view a file in hex. Note if you use the old editor and turn the command line on then many useful 'old' procedures seem to come alive(FSEDIT/FSVIEW....). It really upsets me thet the command line does not work in viewtatble, it does work in the old FS procs, you can even have different function settings in the old procs. All this goes away with EG. You can find more on displaying hex using SAS on my site http://homepage.mac.com/magdelina/.Public/utl.html utl_tipweb.txt /* T000380 VIEWING A FILE IN HEXIDECIMAL IN UNIX AND WINDOWS SAS (3 Methods) |