With Pi Day coming up on 3/14, I wanted to make sure all you SAS programmers know how to use the pi constant in your SAS code...
All you have to do is use constant("pi") in a data step, and you've got the value of pi out to a good many decimal places (probably enough for most any practical scenario). In this example, I let the user specify the value for a circle's radius as a macro variable, and then get the value of the pi constant in a data step, and use that value to calculate the circumference and area of a circle with that radius. I convert those calculated dataset values into macro variables, and use the calculated macro variables in various ways in a GPlot and annotated circle.
Here's the code for doing the calculations and creating the macro variables - hopefully a light bulb is going off in your head right now, and you are thinking of all kinds of ways you could reuse this code!
%let radius=7.0; data foo; pi=constant("pi"); circumference=2*pi*&radius; area=pi*(&radius*&radius); run; proc sql; select unique pi format=comma20.18 into :pi separated by ' ' from foo; select unique circumference format=comma8.3 into :circum separated by ' ' from foo; select unique area format=comma8.3 into :area separated by ' ' from foo; quit; run;
And here's what my graph looks like (here's the code if you'd like to see all the details).
Have a happy pi day!