Note: Only variables listed on the DEFINEKEY and DEFINEDATA methods will be stored in the hash table. Only variables listed on the DEFINEDATA method will be in the output data sets. The order of WORK.NOORDER data set will be in the order the key value was placed into the hash table, not the order of WORK.A.
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.
/* Create sample data */
data a;
input key_date mmddyy6. a d no;
format key_date mmddyy8.;
datalines;
010198 2 3 1
010199 3 2 2
010100 4 1 3
010197 1 4 4
;
data _null_;
/* On the first iteration of the DATA step, create hash tables ASC, DES */
/* and NOORDER. Use the DATASET: argument tag to load WORK.A into each */
/* hash table. Use the ORDERED: argument tag to load the data into the */
/* hash object in the specified manner. The ORDERED: tag is a helpful */
/* way to avoid sorting your data. For each hash object, KEY_DATE will */
/* be the defined KEY and variables A, D and NO will be the data values. */
/* CALL MISSING is used to avoid a NOTE in the log that the defined key */
/* and data values are uninitialized. */
if _n_ = 1 then do;
declare hash asc(dataset: "work.a", ordered:'ascending');
asc.definekey('key_date');
asc.definedata('a','d','no');
asc.definedone();
declare hash des(dataset: "work.a", ordered:'descending');
des.definekey('key_date');
des.definedata('a','d','no');
des.definedone();
declare hash noorder(dataset: "work.a");
noorder.definekey('key_date');
noorder.definedata('a','d','no');
noorder.definedone();
call missing(key_date,a,d,no);
end;
/* Use the OUTPUT method to output each hash object to a new data set. */
rc = asc.output(dataset: 'work.asc');
rc = des.output(dataset: 'work.des');
rc = noorder.output(dataset: 'work.noorder');
run;
title 'original data set';
proc print data=work.a;
run;
title 'ascending data set';
proc print data=work.asc;
run;
title 'descending data set';
proc print data=work.des;
run;
title 'no order data set';
proc print data=work.noorder;
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.
Original data set Obs key_date a d no 1 01/01/98 2 3 1 2 01/01/99 3 2 2 3 01/01/00 4 1 3 4 01/01/97 1 4 4 Ascending data set Obs a d no 1 1 4 4 2 2 3 1 3 3 2 2 4 4 1 3 Descending data set Obs a d no 1 4 1 3 2 3 2 2 3 2 3 1 4 1 4 4 No order data set Obs a d no 1 1 4 4 2 4 1 3 3 2 3 1 4 3 2 2
Type: | Sample |
Topic: | SAS Reference ==> DATA Step SAS Reference ==> Component Objects SAS Reference ==> Component Objects ==> hash object |
Date Modified: | 2012-09-17 15:45:13 |
Date Created: | 2004-09-30 14:09:01 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
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 |