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. The hash table will not include multiple observations of the same key from WORK.A. 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.1 Language Reference: Concepts, Using DATA Step Component Objects.
Click on the link below for additional information.
SAS 9.2 Language
Reference: Concepts, Using DATA Step Component Objects.
/* 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 key values must be unique in a hash object, */
/* so not every record will be loaded into H. 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;
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: | 2009-04-06 12:20:57 |
| 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 |