## How do I keep decimal place precision when multiplying?

Solved
Occasional Contributor
Posts: 11

# How do I keep decimal place precision when multiplying?

Hi SAS Users -

I'm cleaning variables (latitude and longitude) variables before pulling the dataset into ArcMap. Many of the longitude variables are (+) values and need to be converted to (-) values to map accurately in North America.

PROBLEM: I'm losing precision and dropping a decimal place when I do the following.  Any Ideas?

Original value= +118.27436

New value = -118.2744

```if long gt 0 then do;
long2=long*-1.00000;
end;
else do;
long2=long;
end;
run;```

Accepted Solutions
Solution
‎02-15-2017 10:44 PM
Super Contributor
Posts: 268

## Re: How do I keep decimal place precision when multiplying?

No you're not losing precision - the internal representation is fine. It's the external formatted value which is truncated by default.

Try this:

``````data _null_;
long = +118.27436;
if long gt 0 then do;
long2=long*-1.00000;
end;
else do;
long2=long;
end;
put long2= best23.;
run;``````

All Replies
Solution
‎02-15-2017 10:44 PM
Super Contributor
Posts: 268

## Re: How do I keep decimal place precision when multiplying?

No you're not losing precision - the internal representation is fine. It's the external formatted value which is truncated by default.

Try this:

``````data _null_;
long = +118.27436;
if long gt 0 then do;
long2=long*-1.00000;
end;
else do;
long2=long;
end;
put long2= best23.;
run;``````
Occasional Contributor
Posts: 11

## Re: How do I keep decimal place precision when multiplying?

Thanks LaurieF! It worked perfectly and I only had to add a line of syntax.

Posts: 5,543

## Re: How do I keep decimal place precision when multiplying?

The difference is only in the displayed representation. Give both variables the same format and they will display the same.

``````data _null_;
long1 =  +118.27436;
format long1 long2 12.6;
long2 = -abs(long1);
put long1= / long2=;
run;

long1=118.274360
long2=-118.274360
``````
PG
Occasional Contributor
Posts: 11

## Re: How do I keep decimal place precision when multiplying?

Thanks PG Stats!   You're syntax worked too. I just had to tweak it to put it in the Do Loops.

I liked that your syntax resulted in Long and Long2 being side by side in the dataset instead of Long2 being at the end.

I thought I would be able to accept more than one solution but that wasn't the case.

☑ This topic is solved.