SAS author's tip: Specifying a hash iterator object

SAS Hash Object Programming Made EasyMichele Burlew is the author of several highly regarded SAS books including her most recent SAS Hash Object Programming Made Easy. This week, I've selected a short excerpt from her latest book to share with our readers.

If you like this week's free excerpt, be sure to visit Michele Burlew's author page for more information about SAS Hash Object Programming Made Easy,  as well as her many other extremely helpful titles.

The following excerpt is from SAS Press author Michele Burlew's book “SAS Hash Object Programming Made Easy” Copyright © 2012, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. (please note that results may vary depending on your version of SAS software).

Specifying a Hash Iterator Object

When you want to traverse a hash object with a hash iterator object, the first step is to define your hash object and identify key items and data items in the same way as previous examples have shown. If you want SAS to return data in order by the values of the keys, you must add the ORDERED: argument tag to the DECLARE statement and specify its values as “YES”, “ASCENDING”, or “DESCENDING”. Your code can still traverse a hash object if you do not specify the ORDERED: argument tag. However, in this situation, SAS does not retrieve key values from your hash object in either ascending or descending order.

The second action to take in creating a hash iterator object is to add a second DECLARE statement that defines the hash iterator object and associates it with your hash object. This is the only definition-type statement you need to create a hash iterator object. The only argument you supply on this second DECLARE statement is the name of the hash object that you want to traverse. You must always specify the name of the hash object that you want SAS to associate with the hash iterator object, and you must enclose that name in quotation marks.

The syntax of the DECLARE statement that defines a hash iterator object follows. The object-type keyword HITER always immediately follows the DECLARE keyword.

DECLARE HITER iterator-object-name('hash-object-name');

 
tags: Hash Iterator Object, michele burlew, SAS Hash Object, sas press

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <p> <pre lang="" line="" escaped=""> <q cite=""> <strike> <strong>