![]() | ![]() | ![]() | ![]() | ![]() |
Note:
For detailed information regarding object dot programming
in the DATA step, please refer to
SAS 9.2 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 a test data set called LIST whose K1 value equals */
/* the name of the lookup data set. The value of D1 is equal */
/* to the key variable K2 of the lookup data set. */
data list;
input k1 $ d1;
datalines;
mon 2
thurs 4
;
proc print data=list;
title 'List';
run;
/* Create lookup data sets */
data mon;
do k2=1 to 3;
d2=k2+1;
output;
end;
run;
proc print data=mon;
title 'Mon';
run;
data tues;
do k2=1 to 2;
d2=k2*2;
output;
end;
run;
proc print data=tues;
title 'Tues';
run;
data thurs;
do k2=1 to 4;
d2=k2**2;
output;
end;
run;
proc print data=thurs;
title 'Thurs';
run;
data final;
/* On the first iteration of the DATA step, declare the hash object H2. */
/* Note H2 will be instantiated below on every iteration. */
if _n_=1 then do;
declare hash h2;
end;
set list;
/* Specify the LENGTH of the variables defined in the hash object H2. */
length k2 d2 8;
/* Instantiate the hash table H2 with the _NEW_ method. The DATASET: */
/* argument tag loads the appropriate data set based upon the value */
/* of K1 from WORK.LIST into H2. K2 is defined as the 'lookup key'. */
/* K2 and D2 are defined as K2's associated data. Naming K2 in both */
/* the DEFINEKEY and DEFINEDATA method allows K2 to be a variable on */
/* the output data set. */
h2 = _new_ hash(dataset:k1);
h2.defineKey ('k2');
h2.definedata('k2','d2');
h2.defineDone ();
/* Set K2 and D2 to missing to avoid a note in the log that the */
/* specified variables are uninitialized. */
call missing(k2, d2);
/* NOBS contains the number of observations from the lookup data set. */
nobs=h2.num_items;
/* Assign the value of D1 into K2 so when the FIND method */
/* executes, the appropriate data item, D2, will be returned */
/* from the hash table H2. */
k2=d1;
rc=h2.find();
/* Delete the hash table H2 so a new one can be created */
/* in the next iteration of the DATA step. */
rc=h2.delete();
run;
proc print data=final;
title 'Final';
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.
List Obs k1 d1 1 mon 2 2 thurs 4 Mon Obs k2 d2 1 1 2 2 2 3 3 3 4 Tues Obs k2 d2 1 1 2 2 2 4 Thurs Obs k2 d2 1 1 1 2 2 4 3 3 9 4 4 16 Final Obs k1 d1 k2 d2 nobs rc 1 mon 2 2 3 3 0 2 thurs 4 4 16 4 0
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step SAS Reference ==> Component Objects ==> hash object ==> DEFINEDATA SAS Reference ==> Component Objects ==> hash object ==> DEFINEDONE SAS Reference ==> Component Objects ==> hash object ==> DEFINEKEY SAS Reference ==> Component Objects ==> hash object ==> DELETE SAS Reference ==> Component Objects ==> hash object ==> FIND SAS Reference ==> Component Objects ==> hash object ==> NUM_ITEMS Attribute |
| Date Modified: | 2006-06-07 03:03:05 |
| Date Created: | 2005-11-23 14:37:28 |
| Product Family | Product | Host | SAS Release | |
| Starting | Ending | |||
| SAS System | Base SAS | Tru64 UNIX | 9.1 TS1M0 | n/a |
| Linux | 9.1 TS1M0 | n/a | ||
| 64-bit Enabled Solaris | 9.1 TS1M0 | n/a | ||
| HP-UX IPF | 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 | ||
| OpenVMS Alpha | 9.1 TS1M0 | n/a | ||
| z/OS | 9.1 TS1M0 | n/a | ||




