Sample 24647: Perform a fuzzy merge using DATA step component objects
Use the hash iterator to search a hash object for a value
that is close to the value of the look up variable.
Note:
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 starting data */
data one;
input time time5. sample;
datalines;
09:01 100
10:03 101
10:58 102
11:59 103
13:00 104
14:02 105
16:00 106
;
data two;
input time time5. sample;
datalines;
09:00 200
09:59 201
11:04 202
12:02 203
14:01 204
14:59 205
15:59 206
16:59 207
18:00 208
;
/* Use a hash table to determine if TIME from WORK.TWO is within five minutes */
/* of a TIME value from WORK.ONE. */
data out;
length time sample 8;
/* On the first iteration of the DATA step, declare the hash object H and */
/* load it with the data set TWO. TIME is defined as the key variable. */
/* Key variables are not output by default, so TIME is also defined as */
/* associated data, along with SAMPLE. An iterator named HITER is also */
/* declared. CALL MISSING is used to avoid 'variable is uninitialized' */
/* messages in the log for TIME and SAMPLE. */
if _n_=1 then do;
declare hash h(dataset:'two',hashexp:4);
h.definekey('time');
h.definedata('time','sample');
declare hiter hiter('h');
h.definedone();
call missing(time, sample);
end;
/* Read in observations from ONE, but rename the variables TIME and SAMPLE */
set one(rename=(time=time1 sample=sample1));
/* Move to the first item in the hash table. RC=0 result indicates success. */
rc=hiter.first();
do while (rc=0);
/* If the absolute value of TIME1 minus TIME is less than 5 minutes, then */
/* leave the DO WHILE. */
if abs(time1-time) lt 300 then leave;
/* If not, then move to the next item in the hash table and check again */
/* with the new value. */
rc1=hiter.next();
/* If the NEXT() method is not successful, set SAMPLE and TIME to missing */
/* and leave. */
if rc1 ne 0 then do;
sample=.;
time=.;
leave;
end;
end;
run;
proc print;
format time time1 time8.;
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 time sample time1 sample1 rc rc1
1 9:00:00 200 9:01:00 100 0 0
2 9:59:00 201 10:03:00 101 0 0
3 . . 10:58:00 102 0 -2147450842
4 12:02:00 203 11:59:00 103 0 0
5 . . 13:00:00 104 0 -2147450842
6 14:01:00 204 14:02:00 105 0 .
7 15:59:00 206 16:00:00 106 0 0
Use the hash iterator to search a hash object for a value
that is close to the value of the look up variable.
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step SAS Reference ==> Component Objects
|
| Date Modified: | 2006-08-05 03:02:48 |
| Date Created: | 2004-09-30 14:09:00 |
Operating System and Release Information
| Product Family | Product | Host | Starting Release | Ending Release |
| 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 |