DATA Step, Macro, Functions and more

Determine Decimal DIGIT of Variable?

Reply
Contributor
Posts: 59

Determine Decimal DIGIT of Variable?

Hi everyone,

 

I try to determine decimal digit of  my variables which has fractional number. I have a sample data set as below and my desired output also as below.  I don't want to round variiables's values, I just want to cut the decimal part when it comes 6th digit on decimal part.

 

Thank you,

 

Data Sample;
Input Fractional;
Datalines;
1.12345678
2.87654321
3.56781234
4.24135768
5
;
Run;
Data Want;
Set Sample;
Decimal=Round(Fractional,.000001);
Run;

DESIRED

Desired.png

Contributor
Posts: 34

Re: Determine Decimal DIGIT of Variable?

Not elegant, but simple and working: 

Decimal=floor(Fractional*1000000)/1000000;

Respected Advisor
Posts: 3,799

Re: Determine Decimal DIGIT of Variable?

Decimal6=Int(fractional*1e6)/1e6;
Contributor
Posts: 59

Re: Determine Decimal DIGIT of Variable?

Posted in reply to data_null__

Thank you,

 

Could you give more information about  1e6, please?

 

 

 

 

Trusted Advisor
Posts: 1,301

Re: Determine Decimal DIGIT of Variable?

It's scientific notation, 1e6=1000000

In scientific notation, the number before the E is multiplied by the power of ten that is indicated by the number after the E. For example, 2E4 is the same as 2x104 or 20,000. For numeric constants larger than (1032 )-1, you must use scientific notation. Additional examples follow:

http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000780334.htm
Super User
Posts: 11,343

Re: Determine Decimal DIGIT of Variable?

Maybe the easiest is just to pick an appropriate fixed decimal format;

Data Sample;
Input Fractional;
put (Fractional Fractional Fractional) (f10.2 f10.4 f10.6);
Datalines;
1.12345678
2.87654321
3.56781234
4.24135768
5
;
Run;

If you already have the data set and values then just use the desired format for print/report/ other procedure. Then the

 

Ask a Question
Discussion stats
  • 5 replies
  • 126 views
  • 1 like
  • 5 in conversation