Solved
New Contributor
Posts: 4

# Dealing with Scientific Notation

Hello,

I directly import xls files into SAS. One in particular contains three columns, two of which contain numerous results in the format or 0.000005. SAS is using scientific notation to represent 0.000005 as 5E-6 and others such as 0.000003 as 3E-6. I have tried using the following

proc print data=file;

format x 7.;

run;

This is not working. Can anybody help me please? Thank you for your time.

Aoife

Accepted Solutions
Solution
‎09-13-2017 02:10 PM
Super User
Posts: 13,583

## Re: Dealing with Scientific Notation

[ Edited ]

What are the ranges of your numbers? You need to specify a format that will allow sufficient print positions for the smallest number you hope to print. E-6 means decimals so 7. doesn't do much as it says 7 positions of the integer persuasion.

I'd try format 12.8 as a start.

Editor's note: This is a popular topic. We've added a little more information to help new users understand how SAS decides to format your numbers.

The column format, in SAS terms, is a basically an instruction for how to transform a raw value into an appearance that is suitable for a given purpose. A basic attribute of a format is the format length, which controls how much of the value is displayed. For example, a character column might have a storage length of 10 bytes, but a format length of 5 characters (\$5. format), so when you see the formatted values you will see at most 5 characters for each record.

Another attribute of the format is the precision. For example, the DOLLAR8. format will show you up to 8 characters of a value (including a currency symbol and thousands separator) in dollars, but no cents. DOLLAR8.2 will show you the decimal point and the value to the nearest cent (2 decimal spaces). In each case, the value displayed will not exceed 8 characters.

What happens if the formatted value runs into trouble squeezing into 8 characters? SAS drops the thousands separator and currency symbol to free up 2 slots first. If that's not enough, SAS begins to drop precision by lopping off the pennies, then the dimes. If that's still not enough, SAS rounds the value and uses scientific notation and other tricks to save space -- all the while keeping the integrity of your original value for use in any calculations.

For example, run this program:

``````data dollars;
length val1 8 val2 8 val3 8 val4 8;
format val1 DOLLAR8. val2 DOLLAR8.2 val3 DOLLAR4.2 val4 DOLLAR10.2;
val1=12345.67;
val2=12345.67;
val3=12345.67;
val4=12345.67;
run;

proc print;
run;``````

You see these values:

```val1 \$12,346
val2 12345.67
val3 12E3
val4 \$12,345.67```

All Replies
Solution
‎09-13-2017 02:10 PM
Super User
Posts: 13,583

## Re: Dealing with Scientific Notation

[ Edited ]

What are the ranges of your numbers? You need to specify a format that will allow sufficient print positions for the smallest number you hope to print. E-6 means decimals so 7. doesn't do much as it says 7 positions of the integer persuasion.

I'd try format 12.8 as a start.

Editor's note: This is a popular topic. We've added a little more information to help new users understand how SAS decides to format your numbers.

The column format, in SAS terms, is a basically an instruction for how to transform a raw value into an appearance that is suitable for a given purpose. A basic attribute of a format is the format length, which controls how much of the value is displayed. For example, a character column might have a storage length of 10 bytes, but a format length of 5 characters (\$5. format), so when you see the formatted values you will see at most 5 characters for each record.

Another attribute of the format is the precision. For example, the DOLLAR8. format will show you up to 8 characters of a value (including a currency symbol and thousands separator) in dollars, but no cents. DOLLAR8.2 will show you the decimal point and the value to the nearest cent (2 decimal spaces). In each case, the value displayed will not exceed 8 characters.

What happens if the formatted value runs into trouble squeezing into 8 characters? SAS drops the thousands separator and currency symbol to free up 2 slots first. If that's not enough, SAS begins to drop precision by lopping off the pennies, then the dimes. If that's still not enough, SAS rounds the value and uses scientific notation and other tricks to save space -- all the while keeping the integrity of your original value for use in any calculations.

For example, run this program:

``````data dollars;
length val1 8 val2 8 val3 8 val4 8;
format val1 DOLLAR8. val2 DOLLAR8.2 val3 DOLLAR4.2 val4 DOLLAR10.2;
val1=12345.67;
val2=12345.67;
val3=12345.67;
val4=12345.67;
run;

proc print;
run;``````

You see these values:

```val1 \$12,346
val2 12345.67
val3 12E3
val4 \$12,345.67```
New Contributor
Posts: 4

## Re: Dealing with Scientific Notation

Thank you for your reply. What an error. Although having tried format 12.8 and 12.9 the problem remains. The range is from 0 to 0.101879.

Super User
Posts: 13,583

## Re: Dealing with Scientific Notation

Can you post the results of Proc Contents for the data set?

Or post some example lines of your output with x formatted as 12.9?

New Contributor
Posts: 4

## Re: Dealing with Scientific Notation

Okay so after my proc import statement;

proc import DATAFILE= 'file.xls'

DBMS = xls

out=proborig

replace;

run;

Then I have;

proc print data=proborig;

format x 12.9;

run;

and an example of some data lines as a result of this are;

 406 407 408 1189 0 4.3e-05 1190 0.00049 0.00049 1191 0.001322 0.002643 1192 0 0.00081 1194 5e-06 1.1e-05 1195 0.000256 0.000256 1196 0.000277 0.000277

The columns are observation, animal, ancestor and founder respectively.

Thanks again for the help

Super User
Posts: 13,583

## Re: Dealing with Scientific Notation

Proc contents on the data set.

New Contributor
Posts: 4

## Re: Dealing with Scientific Notation

I reassigned the variables to BEST32. with the following code;

data proborig1;

set proborig;

newAnimal = input(Animal, BEST32.);

drop Animal;

rename newAnimal=Animal;

run;

The results of the proc content are;

2 1 3 Ancestor Num 8 Animal Num 8 Founder Num 8

Super User
Posts: 10,787

## Re: Dealing with Scientific Notation

Best32.   ?

Regular Contributor
Posts: 184

## Re: Dealing with Scientific Notation

```xia keshan wrote:

Best32.   ?
```

Yeah. It doesn't really make sense as an informat, but it's accepted as an alias for 32.

Super User
Posts: 8,120

## Re: Dealing with Scientific Notation

That is just how the "BEST" format works.  Apparently it has decided that using scientific notation is the best way to display numbers that small.

🔒 This topic is solved and locked.

Discussion stats
• 9 replies
• 12502 views
• 3 likes
• 5 in conversation