Tips When Using 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.
-
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);
-
The use of a percent character
(%) in the first byte of text output by Java to the SAS log is reserved
by SAS. If you need to output a % in the first byte of a Java text
line, it must be escaped with another percent immediately next to
it (%%).
-
You can have a hash table of hash
tables.
-
A Java object represents an instantiation
of a single Java class. A Java object cannot hold anything else. But
the Java instance can be arbitrarily complicated just like any Java
instance. A Java object can contain references to other Java entities,
but they are not considered Java objects.
-
Copyright © SAS Institute Inc. All Rights Reserved.