![]() | ![]() | ![]() | ![]() | ![]() |
The sample code on the Full Code tab illustrates how to use the hash iterator to search a hash object for a value that is close to the value of the look up variable.
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
;
run;
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
;
run;
/* 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
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step SAS Reference ==> Component Objects SAS Reference ==> Component Objects ==> hash iterator object |
| Date Modified: | 2012-09-05 12:42:12 |
| Date Created: | 2004-09-30 14:09:00 |
| 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 | ||




