| Valid in: | DATA step |
| Category: | Action |
| Type: | Executable |
| Alias: | DCL |
brown for the key 620 and blue for the
key 531. If you use the default, green would be stored for 620 and yellow would be stored for 531.data table;
input key data $;
datalines;
531 yellow
620 green
531 blue
908 orange
620 brown
143 purple
run;
data _null_;
length key 8 data $ 8;
if (_n_ = 1) then do;
declare hash myhash(dataset: "table", duplicate: "r");
rc = myhash.definekey('key');
rc = myhash.definedata('data');
myhash.definedone();
end;
rc = myhash.output(dataset:"otable");
run;ascending' is the same as specifying 'yes'.
yes' is the same as specifying 'ascending'.
dcl hash myhash(suminc: 'count');
declare hash h( );
declare hash h; h = _new_ hash( );
data _null_;
length k $15;
length d $15;
if _N_ = 1 then do;
/* Declare and instantiate hash object "myhash" */
declare hash myhash;
myhash = _new_ hash( );
/* Define key and data variables */
rc = myhash.defineKey('k');
rc = myhash.defineData('d');
rc = myhash.defineDone( );
/* avoid uninitialized variable notes */
call missing(k, d);
end;
/* Create constant key and data values */
rc = myhash.add(key: 'Labrador', data: 'Retriever');
rc = myhash.add(key: 'Airedale', data: 'Terrier');
rc = myhash.add(key: 'Standard', data: 'Poodle');
/* Find data associated with key and write data to log */
rc = myhash.find(key: 'Airedale');
if (rc = 0) then
put d=;
else
put 'Key Airedale not found';
run;data _null_;
length k $15;
length d $15;
if _N_ = 1 then do;
/* Declare and instantiate hash object "myhash" */
declare hash myhash( );
rc = myhash.defineKey('k');
rc = myhash.defineData('d');
rc = myhash.defineDone( );
/* avoid uninitialized variable notes */
call missing(k, d);
end;
/* Create constant key and data values */
rc = myhash.add(key: 'Labrador', data: 'Retriever');
rc = myhash.add(key: 'Airedale', data: 'Terrier');
rc = myhash.add(key: 'Standard', data: 'Poodle');
/* Find data associated with key and write data to log*/
rc = myhash.find(key: 'Airedale');
if (rc = 0) then
put d=;
else
put 'Key Airedale not found';
run;data _null_;
length k $15;
length d $15;
if _N_ = 1 then do;
/* Declare and instantiate hash object "myhash". */
/* Set hash table size to 16. */
declare hash myhash(hashexp: 4);
rc = myhash.defineKey('k');
rc = myhash.defineData('d');
rc = myhash.defineDone( );
/* avoid uninitialized variable notes */
call missing(k, d);
end;
/* Create constant key and data values */
rc = myhash.add(key: 'Labrador', data: 'Retriever');
rc = myhash.add(key: 'Airedale', data: 'Terrier');
rc = myhash.add(key: 'Standard', data: 'Poodle');
rc = myhash.find(key: 'Airedale');
/* Find data associated with key and write data to log*/
if (rc = 0) then
put d=;
else
put 'Key Airedale not found';
run;data x; retain j 999; do i = 1 to 20; output; end; run; /* Using the WHERE option. */ data _null_; length i 8; dcl hash h(dataset: 'x (where =(i > 10))', ordered: 'a'); h.definekey('i'); h.definedone(); h.output(dataset: 'out'); run; /* Using the DROP option. */ data _null_; length i 8; dcl hash h(dataset: 'x (drop = j)', ordered: 'a'); h.definekey(all: 'y'); h.definedone(); h.output(dataset: 'out (where =( i < 8))'); run; /* Using the FIRSTOBS option. */ data _null_; length i j 8; dcl hash h(dataset: 'x (firstobs=5)', ordered: 'a'); h.definekey(all: 'y'); h.definedone(); h.output(dataset: 'out'); run; /* Using the OBS option. */ data _null_; length i j 8; dcl hash h(dataset: 'x (obs=5)', ordered: 'd'); h.definekey(all: 'y'); h.definedone(); h.output(dataset: 'out (rename =(j=k))'); run;