Sunday, August 7, 2011

Using a Function As a Format

A subtle change in the FORMAT procedure in SAS 9.3 makes it possible to use a function as a format.

SAS already allowed you to use another format within a value format. For example, you could create a format that provided special formatted values for the numbers 1 and 2, then formatted all other values with the BEST format. The syntax for this involves writing the format in brackets, for example:

other = [best8.]
To pass the range off to a function instead, write the function name and parentheses inside the brackets. The example in Base SAS 9.3 Procedures Guide suggests creating a function called QFMT (in the FCMP procedure), then using it in a value format, also called QFMT, and defined in this statement:
   value qfmt 

There is only one range, OTHER, in this format because all formatted values are generated by the function.

This approach essentially makes it possible to use all the computational possibilities of the FCMP procedure, but them access the resulting value as a format.

No comments:

Post a Comment