_NEW_ Statement


Creates an instance of a DATA step component object

Valid: in a DATA step

Category: Action

Type: Executable

Syntax

variable = _NEW_ object (< argument_tag-1 : value-1 <, ... argument_tag-n : value-n >>);

Arguments

variable

  • specifies the variable name for the component object.

object

  • specifies the component object. It can be one of the following:

    hash

    indicates a hash object. The hash object provides a mechanism for quick data storage and retrieval. The hash object stores and retrieves data based on look-up keys. For more information about the hash object, see Using the Hash Object in SAS Language Reference: Concepts .

    hiter

    indicates a hash iterator object. The hash iterator object enables you to retrieve the hash object s data in forward or reverse key order. For more information about the hash iterator object, see Using the Hash Iterator Object in SAS Language Reference: Concepts .

argument-tag

  • specifies the information that is used to create an instance of the component object. Valid values for the argument_tag depend on the component object.

    Valid hash object argument tags are

    • hashexp: n

      • The hash object s internal table size, where the size of the hash table is 2 n .

        The value of hashexp is used as a power-of-two exponent to create the hash table size. For example, a value of 4 for hashexp equates to a hash table size of 2 4 , or 16. The maximum value for hashexp is 16, which equates to a hash table size of 2 16 or 65536.

        The hash table size is not equal to the number of items that can be stored. Imagine the hash table as an array of buckets. A hash table size of 16 would have 16 buckets. Each bucket can hold an infinite number of items. The efficiency of the hash table lies in the ability of the hashing function to map items to and retrieve items from the buckets.

        You should set the hash table size relative to the amount of data in the hash object in order to maximize the efficiency of the hash object lookup routines. Try different hashexp values until you get the best result. For example, if the hash object contains one million items, a hash table size of 16 (hashexp = 4) would work, but not very efficiently . A hash table size of 512 or 1024 (hashexp = 9 or 10) would result in the best performance.

      • Default: 8, which equates to a hash table size of 2 8 or 256

    • dataset: dataset_name

      • Names a SAS data set to load into the hash object.

        The name of the SAS data set can be a literal or character variable. The data set name must be enclosed in single or double quotation marks. Macro variables must be enclosed in double quotation marks.

        Note: If the data set contains duplicate keys, then the first instance will be in the hash object, and following instances will be ignored.

    • ordered: option

      • Specifies whether or how the data is returned in key-value order if you use the hash object with a hash iterator object or if you use the hash object OUTPUT method.

      • option can be one of the following values:

        ascending a

        Data is returned in ascending key-value order. Specifying ascending is the same as specifying yes .

        descending d

        Data is returned in descending key-value order.

        YES Y

        Data is returned in ascending key-value order. Specifying yes is the same as specifying ascending .

        NO N

        Data is returned in some undefined order.

      • Default: NO

        • The argument can also be enclosed in double quotation marks.

    • The valid hash iterator object constructor is the hash object name.

Details

To use a DATA step component object in your SAS program, you must declare and create (instantiate) the object. The DATA step component interface provides a mechanism for accessing the hash and hash iterator predefined component objects from within the DATA step.

If you use the _NEW_ statement to instantiate the component object, you must first use the DECLARE statement to declare the component object. For example, in the following lines of code, the DECLARE statement tells SAS that the variable H is a hash object. The _NEW_ statement creates the hash object and assigns it to the variable H.

 declare hash h;  h = _new_ hash( ); 

Note: You can use the DECLARE statement to declare and instantiate a DATA step component object in one step.

A constructor is a method that is used to instantiate a component object and to initialize the component object data. For example, in the following lines of code, the _NEW_ statement instantiates a hash object and assigns it to the variable H. In addition, the hash table size is initialized to a value of 16 (2 4 ) using the argument tag, hashexp.

 declare hash h;  h = _new_ hash(hashexp: 4); 

For more information about the predefined DATA step component objects and constructors, see Using DATA Step Component Objects in SAS Language Reference: Concepts .

Comparisons

The _NEW_ statement instantiates a DATA step component object. The DECLARE statement declares a DATA step object.

Examples

This example uses the _NEW_ statement to instantiate and initialize data for a hash object and instantiate a hash iterator object.

The hash object is filled with data, and the iterator is used to retrieve the data in key order.

 data kennel;     input name -10 kenno -15;     datalines;  Charlie      15  Tanner       07  Jake         04  Murphy       01  Pepe         09  Jacques      11  Princess Z   12  ;  run;  data _null_;     if _N_ = 1 then do;        length kenno ;        length name ;        /* Declare the hash object */        declare hash h;        /* Instantiate and initialize the hash object */   h = _new_ hash(hashexp: 4, dataset:"work.kennel", ordered: 'yes');   /* Declare the hash iterator object */        declare hiter iter;        /* Instantiate the hash iterator object */        iter = _new_ hiter('h');        /* Define key and data variables */        h.defineKey('kenno');        h.defineData('name', 'kenno');        h.defineDone();        /* avoid uninitialized variable notes */        call missing(kenno, name);     end;     /* Find the first key in the ordered hash object and output to the log */     rc = iter.first();     do while (rc = 0);        put kenno '   ' name;        rc = iter.next();     end;  run; 

See Also

Statements:

  • DECLARE Statement on page 1133

Using DATA Step Component Objects in SAS Language Reference: Concepts

Appendix 1, DATA Step Object Attributes and Methods, on page 1633




SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 704

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net