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 2011, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 17 Feb 2011 09:55:35 -0500
Reply-To:     Nat Wooding <nathani@VERIZON.NET>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Nat Wooding <nathani@VERIZON.NET>
Subject:      Re: Counting digits
In-Reply-To:  <201102171442.p1HAIfWb004282@waikiki.cc.uga.edu>
Content-Type: text/plain; charset="US-ASCII"

Art

You are correct. A log of a negative number is missing.

Nat

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Arthur Tabachneck Sent: Thursday, February 17, 2011 9:42 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Counting digits

Lorne,

I don't think the Nat/Howard solution will work with negative numbers unless you add the abs function as well.

Art ------- On Thu, 17 Feb 2011 09:30:36 -0500, Lorne Klassen <lk1@ROGERS.COM> wrote:

>I like this (from Nat and modified by Howard S): > >numbers = int( log10( y ) ) + 1; > >thanks > > >On Thu, 17 Feb 2011 07:20:23 -0500, Nat Wooding <nathani@VERIZON.NET> wrote: > >>Lorne >> >>The INT would be a definite improvement to my code. >> >>Nat >> >>-----Original Message----- >>From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Lorne >>Klassen >>Sent: Wednesday, February 16, 2011 11:51 PM >>To: SAS-L@LISTSERV.UGA.EDU >>Subject: Re: Counting digits >> >>Thanks Tom and Nat. Be careful with this though: >> >>length(left(put(abs(y),20.))) >> >>which won't work in rare cases. E.g., if y=99999.99 then PUT will round and >>return 100000 and the result will be 6 instead of the correct value, 5. >> >>That's why I apply the INT function first. >> >> >>On Wed, 16 Feb 2011 22:55:23 -0500, Tom Abernathy <tom.abernathy@GMAIL.COM> >>wrote: >> >>>To deal with the negative numbers add an ABS() function call. >>> >>>Also could just use >>> >>> length(left(put(abs(y),20.))) >>> >>>Which does not seem to get confused by 10,000,000. >>> >>>On Wed, 16 Feb 2011 22:07:46 -0500, Nat Wooding <nathani@VERIZON.NET> >>wrote: >>> >>>>Lorne >>>> >>>>The following seems to work ok. >>>> >>>>Nat Wooding >>>> >>>> >>>>data num; >>>>input y ; >>>>numbers = ceil( log10( y + .1 ) ); >>>>format y comma15.; >>>>* the addition of the .1 was needed to get the 10000000 to work; >>>>cards; >>>>7 >>>>76 >>>>768 >>>>6000 >>>>6500 >>>>6900 >>>>7687 >>>>76877.234 >>>>800000 >>>>899999 >>>>9000000 >>>>10000000 >>>>100000000 >>>>run; >>>> >>>>-----Original Message----- >>>>From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of >Lorne >>>>Klassen >>>>Sent: Wednesday, February 16, 2011 6:47 PM >>>>To: SAS-L@LISTSERV.UGA.EDU >>>>Subject: Counting digits >>>> >>>>Simple question: I want to get the number of digits to the left of the >>>>decimal place from a value in a numeric variable (excluding negative sign >>>>if there is one). >>>> >>>>I can live with the following which works but I'm wondering if it can be >>>>even simpler than this? I thought there might be a numeric function to do >>>>it directly but couldn't find one. >>>> >>>>y = 76877.234; >>>>result = countc(put(int(y),32.),,"d"); >>>> or >>>>result = length(compress(put(int(y),32.)," -"));


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