Sample 24667: Load a SAS DATA set into a hash object and create a SAS DATA set from a hash object
Illustrate the DATASET constructor and the OUTPUT method.
Note: Only variables listed on the DEFINEKEY and DEFINEDATA methods will be stored in the hash table. By default, the hash table will not include multiple records of the same key from WORK.A. (Starting with SAS 9.2 you can use the MULTIDATA: 'YES' argument tag on the DECLARE statement to allow multiple records with the same key value.) The first observation of a key will be added to the hash table. Only variables listed on the DEFINEDATA method will be in the output data set WORK.OUT
For detailed information regarding object dot programming in the DATA step, please refer to SAS 9.3 Component Objects: Reference.
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.
/* Create sample data */
data a;
input key a b c;
datalines;
1 10 100 9
1 20 200 8
2 10 100 9
3 10 100 9
4 10 100 9
4 20 200 8
;
data _null_;
/* On the first iteration of the DATA step, create a hash table called H */
/* and load it with the values from WORK.A. Define the KEY and DATA */
/* values for H. Note that by default, key values must be unique in a */
/* hash object, so not every record will be loaded into H. (Starting in */
/* SAS 9.2, the MULTIDATA: 'YES' argument tag can be used on the DECLARE */
/* statement to allow multiple records with the same key value in a hash */
/* object.) Also, only those variables defined in DEFINEDATA will be */
/* output to WORK.OUT. Use CALL MISSING to avoid the NOTE in the log that*/
/* the specified variables were uninitialized. An assignment statement */
/* for these variables would work as well. */
if _n_ = 1 then do;
declare hash h(dataset: "work.a");
h.definekey('key');
h.definedata('a','b');
h.definedone();
call missing(key,a,b);
end;
/* Use the OUTPUT method to output the records from the hash object H to */
/* the data set WORK.OUT. */
rc = h.output(dataset: "work.out");
run;
/* Note, neither KEY nor C will be in WORK.OUT because they were not */
/* defined in the DEFINEDATA method in the step above. */
proc print data=work.out;
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.
Obs a b
1 10 100
2 10 100
3 10 100
4 10 100
Illustrate the DATASET constructor and the OUTPUT method.
Type: | Sample |
Topic: | SAS Reference ==> DATA Step SAS Reference ==> Component Objects ==> hash object SAS Reference ==> Component Objects ==> hash object ==> DEFINEDATA SAS Reference ==> Component Objects ==> hash object ==> DEFINEKEY SAS Reference ==> Component Objects ==> hash object ==> OUTPUT
|
Date Modified: | 2012-04-02 14:11:10 |
Date Created: | 2004-09-30 14:09:02 |
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 |