@Fae wrote:
I am having trouble with the removedup command in Hash. From what I understand, it remove the current record being pointed in the hash table(memory) and set the pointer to null. Am I missing anything?
Yes, you are. There are, unfortunately, even more details about the REMOVEDUP method than can be found in the documentation. It took me quite some testing to investigate these details (using SAS 9.4 TS1M2).
For example, you may be wondering what the purpose of the "key: ..." argument of the method is, when actually the pointer specifies the hash entry to be removed, as you mentioned.
Indeed, the pointer must be set, regardless of the argument (as long as it is valid) and regardless of values of key variables. (Otherwise you get the "WARNING: No current list item has been set ...".) The effect of the REMOVEDUP method then depends on the type of entry the pointer points to:
Case 1: It belongs to a group of >=2 entries with the same key.
Effect: This entry is removed, unless an error occurs because the group (!) is locked by an iterator or the key argument is invalid (type mismatch or incorrect number of values.) Valid key arguments or values of key variables are ignored, including the case of non-existing key values. The return code is 0.
Case 2: Its key occurs only once in the hash object (still assuming MULTIDATA: 'YES').
Effect: In this case REMOVEDUP acts in the same way as REMOVE! Which means: Now it is the pointer which is ignored henceforth. If an existing key is specified in the argument or (with empty argument) in the key variables, all (!) hash items with this key are removed (and the return code is set to 0), again unless locked by an iterator. If a non-existing (but valid) key is specified, nothing is removed and only in this case the return code is different from 0 (causing an error message if not written to a variable). An invalid key causes error messages.
... View more