Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- Graphics
- /
- Converting projected coordinates to polar coordinates

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 03-22-2017 10:45 AM
(2379 views)

Hi ,

I have a small query related to the output of %centroid macro. I need to know the units of the X-Y output from %centroid. Actually I want latitude & longitude of the centroid. For those reasons, I need to convert X-Y coordinates to polar coordinates. Do you have any idea how can I convert output form %centroid macro to polar coordinates?

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I believe the centroid macro returns x/y centroids in whatever the units the x/y were in the original map.

Some of the SAS maps have long & lat variables, in addition to the x & y variables, that you would need to make use of ...

With the old traditional maps (in the maps library), such as maps.states, the x/y are projected values, and would not be much use to you. If you pre-process this map, and replace the projected x/y with the long/lat variables (which are in radians), then the centroid macro will return x/y in radians, and you could use the tip in the previous comment to convert to degrees.

With the new GfK maps (in the mapsgfk library), such as mapsgfk.us_states, the x/y are also projected values, and would not be much use to you either. If you pre-process this map, and replace the projected x/y with the long/lat variables (which are in degrees), then the centroid macro will return x/y in degrees.

3 REPLIES 3

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

the conversion from cartesian to polar coordinate systems is an easy trig problem for SAS. I am not sure this is what you want, because i am not sure what %CENTROID produces, but the following will convert back and forth. Remember SAS uses radians as the measure of the angle so you may need to convert from degrees if you start at polar coords.

```
data have;
input x y;
datalines;
12 5
5 12
run;
data wantpolar;
set have;
r = sqrt(x**2 +y**2);
alpha=atan(y/x); /* angle in radians */
degrees = alpha*(180/constant('pi')); /* radians to degrees */
* Polar to cartesian;
x1 = r*cos(alpha);
y1 = r*sin(alpha);
run;
proc print data=wantpolar;
run;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I believe the centroid macro returns x/y centroids in whatever the units the x/y were in the original map.

Some of the SAS maps have long & lat variables, in addition to the x & y variables, that you would need to make use of ...

With the old traditional maps (in the maps library), such as maps.states, the x/y are projected values, and would not be much use to you. If you pre-process this map, and replace the projected x/y with the long/lat variables (which are in radians), then the centroid macro will return x/y in radians, and you could use the tip in the previous comment to convert to degrees.

With the new GfK maps (in the mapsgfk library), such as mapsgfk.us_states, the x/y are also projected values, and would not be much use to you either. If you pre-process this map, and replace the projected x/y with the long/lat variables (which are in degrees), then the centroid macro will return x/y in degrees.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks everyone for replying back. The answers were really helpful. Thanks

Are you ready for the spotlight? We're accepting content ideas for **SAS Innovate 2025** to be held May 6-9 in Orlando, FL. The call is **open **until September 25. Read more here about **why** you should contribute and **what is in it** for you!

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.