Published on :
Macro MIXTE

Macro makehash - Hash Object Initialization

This code is also available in: Deutsch Español Français
This macro aims to simplify the declaration of Hash Objects within a Data step. It handles the declaration, the definition of key and data variables, as well as the initialization of variables via 'call missing'.
Technical note: The provided code contains a dependency on external sub-macros not defined here (%cvarlens, %quotelst, %commas). Furthermore, there appears to be an inconsistency in the macro body: methods (defineKey, defineData) are called on the literal identifier 'class' instead of using the macro parameter '&hashname', which would restrict its functionality if the object is not named 'class'.
Data Analysis

Type : MIXTE


The macro is designed to load any SAS dataset specified by the '&ds' parameter into the Hash object.

1 Code Block
MACRO
Explanation :
Macro definition. It prepares variable lengths (via %cvarlens), instantiates the Hash object pointing to the '&ds' dataset, defines keys and data (via the .defineKey and .defineData methods), and finalizes with .defineDone. The 'call missing' call avoids uninitialized variable messages.
Copied!
1%macro makehash(hashname,ds,keyvars,datavars);
2LENGTH %cvarlens(&ds,&datavars);
3IF _n_=1 THEN DO;
4 declare hash &hashname(dataset: "&ds");
5 _rc = class.defineKey(%commas(%quotelst(&keyvars)));
6 _rc = class.defineData(%commas(%quotelst(&datavars)));
7 _rc = class.defineDone();
8 call missing(%commas(&datavars));
9END;
10%mend makehash;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Author: Roland Rashleigh-Berry (2014) - Public domain software.