Sample 24758: Store and retrieve data from the DATA step hash object
Illustrate using the DECLARE statement and the ADD and
FIND methods using Object Dot Syntax.
Note:
The following example uses the ADD method to store data
from variable D and it's associated "key", variable K,
into the hash object named HASH.
The FIND method is used to retrieve data associated with
the key value 'Homer'.
For detailed information regarding object dot programming
in the DATA step, please refer to SAS 9.1 Language
Reference: Concepts, Using DATA Step Component Objects.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
data _null_;
length d $20;
length k $20;
/* Declare and instantiate the hash object and key and data variables */
if _n_ = 1 then do;
declare hash h(hashexp: 4);
rc = h.definekey('k');
rc = h.definedata('d');
rc = h.definedone();
call missing(k,d);
end;
/* Define constant value for key K and data D */
k = 'homer';
d = 'odyssey';
/* Use the add method to add the key and data to the hash object */
rc = h.add();
if (rc ne 0) then put 'add failed.';
/* Define constant value for key K and data D */
k = 'joyce';
d = 'ulysses';
/* Use the add method to add the key and data to the hash object */
rc = h.add();
if (rc ne 0) then put 'add failed.';
k = 'homer';
/* Use the find method to retreive the data associated with key value 'homer' */
rc = h.find();
if (rc = 0) then put d=;
else put 'key equal to homer not found.';
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
OUTPUT to SAS log
d=Odyssey
Illustrate using the DECLARE statement and the ADD and
FIND methods using Object Dot Syntax.
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step SAS Reference ==> Component Objects SAS Reference ==> Component Objects ==> hash object
|
| Date Modified: | 2012-09-17 15:45:30 |
| Date Created: | 2004-09-30 14:09:11 |
Operating System and Release Information
| SAS System | Base SAS | Tru64 UNIX | 9.1 TS1M0 | n/a |
| OpenVMS Alpha | 9.1 TS1M0 | n/a |
| HP-UX IPF | 9.1 TS1M0 | n/a |
| Linux | 9.1 TS1M0 | n/a |
| 64-bit Enabled Solaris | 9.1 TS1M0 | n/a |
| 64-bit Enabled HP-UX | 9.1 TS1M0 | n/a |
| 64-bit Enabled AIX | 9.1 TS1M0 | n/a |
| Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.1 TS1M0 | n/a |
| z/OS | 9.1 TS1M0 | n/a |