Date: Wed, 16 Feb 2011 22:07:46 -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: <201102162347.p1GKBAVR023578@waikiki.cc.uga.edu>
Content-Type: text/plain; charset="US-ASCII"
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.)," -"));