PROC FCMP User-Defined Functions by Troy Martin Hughes

PROC FCMP User-Defined Functions by Troy Martin Hughes

Author:Troy Martin Hughes
Language: eng
Format: epub
Publisher: SAS Institute


Note the simplicity of the functional approach to multivariable initialization. A single, unassuming line of code delivers equivalent functionality to two SORT procedures and a DATA step, or to a SQL procedure having several lines of code! Thus, the exceptional speed of in-memory hash lookups has been encapsulated within the subroutine implementation, which yields a more concise, readable DATA step.

Counting Hash Keys

In previous examples, the role of a hash object has been to confirm that a key exists inside a hash object, or to return associated values when a key exists. Hash objects can also be used, however, to count keys. By incrementing a specific key’s count each time it is encountered (that is, passed as an argument to the function instantiating the hash object), a hash object can operationalize a frequency table.

DATA step hash functionality provides the built-in hash SUM method and the associated DECLARE statement SUMINC argument, which in combination can be used to build frequency table hash objects. Unfortunately, neither the SUM method nor the SUMINC argument are supported by FCMP hash functionality. Fortunately, equivalent functionality can be engineered within the FCMP procedure from more basic hash building blocks.

For example, consider the requirement to evaluate word frequency in the Gettysburg Address, and more specifically, to find the modal word—the most frequently occurring word in the speech. Program 4.20 creates the Gettys data set in which the Text variable holds the text of the Gettysburg Address.

Program 4.20: Gettysburg Address

data gettys;

length text $10000;

text="Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we can not dedicate — we can not consecrate — we can not hallow — this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us — that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion — that we here highly resolve that these dead shall not have died in vain — that this nation, under God, shall have a new birth



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.