BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
eap
Obsidian | Level 7 eap
Obsidian | Level 7

 

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;
1 ACCEPTED SOLUTION

Accepted Solutions
LaurieF
Barite | Level 11

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;

View solution in original post

4 REPLIES 4
LaurieF
Barite | Level 11

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;
eap
Obsidian | Level 7 eap
Obsidian | Level 7

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

PGStats
Opal | Level 21

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
eap
Obsidian | Level 7 eap
Obsidian | Level 7

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.

SAS Innovate 2025: Register Now

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1120 views
  • 2 likes
  • 3 in conversation