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;
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;
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;
Thanks LaurieF! It worked perfectly and I only had to add a line of syntax.
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
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.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.