Monday 8 February 2010

NOTE: The DIVIDE Function

At the risk of stumbling over the description of another "new" function, I discovered the DIVIDE function alongside my discovery of the IFC/IFN functions. This is definitely new in V9.2; confirmed by the What's New in the Base SAS 9.2 Language web page.

It caught my eye because it handles those division scenarios where SAS normally issues notes or warnings to the log, e.g. divide by zero. In many cases you would want to be warned of missing values and divide by zero, there are some cases where you do not, but you need to create long-winded conditional coding around your division in order to avoid the messages. Well, with the DIVIDE function you don't.

Instead of returning notes or warnings, the DIVIDE function returns a special missing value. For example, it might return .I (indicating infinity) or .M (minus infinity). The full range of values and circumstances are in the DIVIDE documentation. The special missing values are understood by ODS too, and handled nicely. Typically, when SAS prints special missing values, it omits the dot and just prints the upper-cased letter.

If you're not familiar with special missing values (they're not new in V9.2, they've been around for many, many years), take a look at the V9.2 documentation "Creating Special Missing Values".

The DIVIDE function won't be useful to everybody, but for some SAS coders it'll be received with thanks.