/* Richard A. DeVenezia * www.devenezia.com * * Originally posted to SAS-L Nov 20, 2003 Small warning on use of constant() in a loop, don't. The data step compiler does not recognize and optimize a constant() call with a constant argument. A smart compiler would move the function evaluation outside the loop. Heck, the static portion of the expression should be compiled and not left for resolution at runtime. If it ain't gonna change, compute it once. One (flippant) definition of insanity is: - Doing the same thing over and over again, expecting a different result I am particularly disturbed that the compiler is not exhibiting smarts. This lack of smarts has nothing to do with constant() function and is fundamental in nature. A slow to fast continuum observed in both 8.2 and 9.0 during repeated runs on a Windows 2000 machine on P4 3.06g and 1g of 333mhz memory. */ * drop this down a magnitude if not on very fast (circa 2003) system; %let max=1e8; * inside, slow; data _null_; do p = 1 to &max; theta = 2*constant('PI') * p/&max; end; stop; run; * outside, fast; data _null_; pi = constant ('PI'); do p = 1 to &max; theta = 2*pi * p/&max; end; stop; run; * compiled as constant inside, faster; data _null_; do p = 1 to &max; theta = 2*%sysfunc(constant(PI)) * p/&max; end; stop; run; * premultiply by 2 and predivide by max since they are constants, even faster; %let factor = %sysevalf(2*%sysfunc(constant(PI))/&max); data _null_; do p = 1 to &max; theta = &factor * p; end; stop; run;