Previous Page | Next Page

Hash and Hash Iterator Object Language Elements

CLEAR Method



Removes all items from the hash object without deleting the hash object instance.
Applies to: Hash object

Syntax
Arguments
Details
Examples
See Also

Syntax

rc=object.CLEAR();


Arguments

rc

specifies whether the method succeeded or failed.

A return code of zero indicates success; a nonzero value indicates failure. If you do not supply a return code variable for the method call and the method fails, then an appropriate error message is written to the log.

object

specifies the name of the hash object.


Details

The CLEAR method enables you to remove items from and reuse an existing hash object without having to delete the object and create a new one. If you want to remove the hash object instance completely, use the DELETE method.

Note:   The CLEAR method does not change the value of the DATA step variables. It only clears the values in the hash object.  [cautionend]


Examples

The following example declares a hash object, gets the number of items in the hash object, and then clears the hash object without deleting it.

data mydata;                                                                         
 do i = 1 to 10000;                                                             
   output;                                                                      
 end;                                                                           
run;                                                                            

data _null_;                                                                    
 length i 8;
                                                                    
/* Declares the hash object named MYHASH using the data set MyData. */
dcl hash myhash(dataset: 'mydata');                                                      
 myhash.definekey('i');                                                              
 myhash.definedone();
 call missing (i);                                                                

/* Uses the NUM_ITEMS attribute, which returns the number of items in the hash object. */
 n = myhash.num_items;                                                               
 put n=;                                                                        

/* Uses the CLEAR method to delete all items within MYHASH. */
 rc = myhash.clear();                                                                

/* Writes the number of items in the log. */
 n = myhash.num_items;                                                               
 put n=;                                                                        

 run; 

The first PUT statement writes the number of items in the hash table MYHASH before it is cleared.

n=10000

The second PUT statement writes the number of items in the hash table MYHASH after it is cleared.

n=0


See Also

Methods:

DELETE Method

Previous Page | Next Page | Top of Page