LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (September 2004, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 24 Sep 2004 16:01:55 -0400
Reply-To:     Howard Schreier <Howard_Schreier@ITA.DOC.GOV>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Howard Schreier <Howard_Schreier@ITA.DOC.GOV>
Subject:      Re: How to get decimal places out of a numeric value

I agree.

Here's the most general way I can think of to derive an answer via numeric- to-character conversion:

data _null_; do n = ., 1/3, 1, 2, 3.45, 6000000; c = put(n,e32.); p = max(length(translate(scan(c,1,'E'),' ','0') ) - input(scan(c,2,'E'),3.) - 3 , 0); put n best32. +1 c= p=; end; run;

Result:

. c=. p=0 0.33333333333333 c=3.3333333333333000000000000E-01 p=14 1 c=1.0000000000000000000000000E+00 p=0 2 c=2.0000000000000000000000000E+00 p=0 3.45 c=3.4500000000000000000000000E+00 p=2 6000000 c=6.0000000000000000000000000E+06 p=0

On Thu, 23 Sep 2004 15:28:17 -0600, Jack Hamilton <JackHamilton@FIRSTHEALTH.COM> wrote:

>If you have stored the number as a character variable, you can use the >indexc function or the scan function to find the location of the decimal >point, as was mentioned earlier. There are probably half a dozen ways >to do that (at least). > >If the variable is stored as a number, it's not possible to obtain the >number of significant digits to the right of the decimal, as SAS doesn't >retain that information. All numbers are stored as floating point. You >can convert the number to a string and count the digits to the right of >the decimal point, but the answer will depend on the format you chose to >use (or that SAS used by default). > >Take the number 12.350. It might be displayed as 12.6, 12.35, 12.350, >or 12.350000. > >Some numbers created by calculations, such as 1/3, in "reality" have as >many significant digits as you might care to want. > > > > > >-- >JackHamilton@FirstHealth.com >Manager, Technical Development >Metrics Department, First Health >West Sacramento, California USA > >>>> "Bob Lan" <baoxian_lan@EXCITE.COM> 09/23/2004 1:08 PM >>> >Dear all, > >Do you know how can I get decimal places out of a variable value? For >example, I want to know it is 3 from 123.123. I have tried the >following. But those did not work for me. > > > >proc means data=sashelp.class noprint; > class sex; > var height; > output out=htmean n=_n mean=_mean median=_median std=_std min=_min >max=_max; >run; > >data _null_; > set htmean; > > x=vformatd(_median); > > put x=; >run; > >proc sql noprint; > select format into: fmt > from dictionary.columns > where libname='WORK' and > memname='HTMEAN' and > name ='_median'; >quit; > >%put ***&fmt***;


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