Component Objects |
You can assign objects in the same manner as you assign DATA step variables. However, the object types must match. The first set of code is valid, but the second generates an error.
declare hash h(); declare hash t(); t=h;
declare hash t(); declare javaobj j(); j=t;
You cannot declare arrays of objects. The following code would generate an error:
declare hash h1(); declare hash h2(); array h h1-h2;
You can store a component object in a hash object as data but not as keys.
data _null_; declare hash h1(); declare hash h2(); length key1 key2 $20; h1.defineKey('key1'); h1.defineData('key1', 'h2'); h1.defineDone(); key1 = 'abc'; h2 = _new_ hash(); h2.defineKey('key2'); h2.defineDone(); key2 = 'xyz'; h2.add(); h1.add(); key1 = 'def'; h2 = _new_ hash(); h2.defineKey('key2'); h2.defineDone(); key1 = 'abc'; rc = h1.find(); h2.output(dataset: 'work.h2'); run; proc print data=work.h2; run;
The data set WORK.H2 is displayed.
Obs key2 1 xyz
You cannot use component objects with comparison operators other than the equal sign (=). If H1 and H2 are hash objects, the following code will generate an error:
if h1>h2 then
After you declare and instantiate a component object, you cannot assign a scalar value to it. If J is a java object, the following code will generate an error:
j=5;
You have to be careful to not delete object references that might still be in use or that have already been deleted by reference. In the following code, the second DELETE statement will generate an error because the original H1 object has already been deleted through the reference to H2. The original H2 can no longer be referenced directly.
declare hash h1(); declare hash h2(); declare hash t(); t=h2; h2=h1; h2.delete(); t.delete();
You cannot use component objects in argument tag syntax. In the following example, using the H2 hash object in the ADD methods will generate an error.
declare hash h2(); declare hash h(); h.add(key: h2); h.add(key: 99, data: h2);
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.