## SAS Graphs 3D

How to plot the below equations in SAS?

x=r*sin(theta)*cos(theta1)

y=r*sin(theta)*sin(theta1)

z=r*cos(theta)

Help needed.

1 ACCEPTED SOLUTION

Accepted Solutions

## Re: SAS Graphs 3D

If you are interested in polar equations (2D), that is easily done. For example, the following create a "polar rose":

``````%let k = 5;
data Rose;
do theta = 0 to 2*constant("pi") by 0.01;
r = cos(&k * theta);
x = r*cos(theta);
y = r*sin(theta);
output;
end;
run;

title "Polar Rose: r = cos(&k theta)";
proc sgplot data=Rose aspect=1;
series x=x y=y;
refline 0 / axis=x;
xaxis min=-1 max=1;
refline 0 / axis=y;
yaxis min=-1 max=1;
run;
``````
5 REPLIES 5

## Re: SAS Graphs 3D

Spherical coordinate are an alternate coordinate system in which points in 3D space are represented by a distance from the origin, a polar angle, and an azimuthal angle.  This coordinate system is used for radially symmetric problems in physics and geometry. In SAS, it arises naturally when you want to plot maps. For maps, the radius of the earth is assumed to be constant, and there are many many projections that you can use to visualize the surface of the earth in the flat plane of the screen.

For a fixed radius, r, your equations form a sphere of radius r.  You could draw a 3D scatter plot of the image of a dense grid of (theta1, theta) values to see what it looks like, but since all spheres look like spheres there really isn't much point in graphing it.

If you tell us your application, we might be able to provide more information. Do you have 3D data that you are trying to model? Are you trying to estimate the radius of "best fit" for a set of data points? Are you trying to visualize 3D data?

## Re: SAS Graphs 3D

I don't have any data, was thinking how could we plot polar equations in SAS.

## Re: SAS Graphs 3D

If you are interested in polar equations (2D), that is easily done. For example, the following create a "polar rose":

``````%let k = 5;
data Rose;
do theta = 0 to 2*constant("pi") by 0.01;
r = cos(&k * theta);
x = r*cos(theta);
y = r*sin(theta);
output;
end;
run;

title "Polar Rose: r = cos(&k theta)";
proc sgplot data=Rose aspect=1;
series x=x y=y;
refline 0 / axis=x;
xaxis min=-1 max=1;
refline 0 / axis=y;
yaxis min=-1 max=1;
run;
``````

## Re: SAS Graphs 3D

I wrote a blog post on the subject of polar roses: "Lo, how a polar rose e'er blooming."  Jay54
Meteorite | Level 14

## Re: SAS Graphs 3D

Earlier in the year, I wrote an article on creating 3D graphs using SAS 9.4 SGPLOT.  This includes a macro that can handle a simple 3D scatterplot, and a way to animate it.  You might find some useful ideas here.

http://blogs.sas.com/content/graphicallyspeaking/2015/03/10/a-3d-scatter-plot-macro/

http://blogs.sas.com/content/graphicallyspeaking/2015/03/16/a-3d-scatter-plot-animation-macro/

Discussion stats
• 5 replies
• 2142 views
• 2 likes
• 3 in conversation