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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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