# SAS author's tip: Computing some useful constants

This first SAS tip of 2013 comes from the illustrious Ron Cody and his bestselling book Learning SAS by Example: A Programmer's Guide. I hope you'll find this excerpt helpful- as well as all of our future weekly tips on this blog. Here's to a great year!

The following excerpt is from SAS Press author Ron Cody and his book "Learning SAS by Example: A Programmer's Guide" Copyright © 2007, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. (please note that results may vary depending on your version of SAS software)

Computing Some Useful Constants

The CONSTANT function returns values of commonly used mathematical constants such as pi and e. For a SAS programmer, perhaps the most useful feature of this function is its ability to compute the largest integer that can be stored in less than 8 bytes. The next program demonstrates some of the more common uses of this function:
Pi and e are computed as shown here. To compute the largest integer stored in n bytes, you provide a second argument indicating the number of bytes. Output from this program is shown as follows:
To be sure the exact integer feature of this function is clear, if you use a LENGTH statement to set the length of a numeric variable to 3, the largest integer you can represent without losing accuracy is 8,192; with a length of 4, you can represent integers up to 2,097,152. (Remember that these values may vary, depending on your operating system.)

View some previously featured tips from Ron Cody's work on this blog: Using informats to filter invalid valuesA short-cut for requesting multiple tablesCreating a bar chart using PROC SGPLOT, Computing a new variable with PROC REPORT, and SPEDIS and fuzzy matching.

1. [...] additional SAS tips from Ron Cody's books that have been featured on this blog: Computing some useful constants; Using informats to filter invalid values; A short-cut for requesting multiple tables and [...]