Previous Page | Next Page

Hash and Hash Iterator Object Language Elements

NUM_ITEMS Attribute



Returns the number of items in the hash object.
Applies to: Hash object

Syntax
Arguments
Examples

Syntax

variable_name=object.NUM_ITEMS;


Arguments

variable_name

specifies the name of the variable that contains the number of items in the hash object.

object

specifies the name of the hash object.


Examples

This example creates a data set and loads the data set into a hash object. An item is added to the hash object and the total number of items in the resulting hash object is returned by the NUM_ITEMS attribute.

data work.stock;
   input item $1-10 qty $12-14;
   datalines;
broccoli 345
corn 389
potato 993
onion 730
;

data _null_;
   if _N_ = 1 then do;
      length item $10;
      length qty 8;
      length totalitems 8;
      /* Declare hash object and read STOCK data set as ordered */
      declare hash myhash(dataset: "work.stock");
      /* Define key and data variables */
      myhash.defineKey('item');
      myhash.defineData('qty');
      myhash.defineDone();
   end;
   /* Add a key and data value to the hash object */
   item = 'celery';
   qty = 183;
   rc = myhash.add();
   if (rc ne 0) then
      put 'Add failed';
   /* Use NUM_ITEMS to return updated number of items in hash object */
   totalitems = myhash.num_items;
   put totalitems=;
run;

totalitems=5 is written to the SAS log.

Previous Page | Next Page | Top of Page