Using POINT= to trace 'parent-child' lineage in a data set." />
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
Note: The new variable created can be used by other steps as a BY variable.
The values of the keys of the hash table must be unique.
See also Execute a 'chained' lookup using a hash table.
For detailed information regarding object dot programming in the DATA step, please refer to the SAS 9.3 Component Objects: Reference.
For releases prior to SAS 9.1, see Using POINT= to trace 'parent-child' lineage in a data set
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.
data transactions;
infile datalines truncover;
input start_loc $ 1-12 start_time time5. end_loc :$12. end_time :time5. shipment;
datalines;
Albany 05:00 50
Denver 10:00 Lansing 12:15 15
Albany 05:00 Denver 10:00 300
Atlanta 12:00 Tallahassee 13:00 10
Tallahassee 13:00 Springfield 18:00 38
Bismarck 15:00 Lansing 18:00 2
Atlanta 12:00 1000
Springfield 18:00 Bismarck 20:30 24
Bismarck 20:30 Helena 23:30 90
Denver 12:45 30
Denver 12:45 Bismarck 15:00 45
Lansing 18:00 Springfield 24:00 200
;
data trans_plus_ids;
/* Define the attributes of the variables for the hash tables */
if _n_=0 then set transactions;
keep start_loc start_time end_loc end_time shipment id;
/* Create empty START and TRANS hash tables */
declare hash start();
start.defineKey('end_loc', 'end_time');
start.defineData('end_loc', 'end_time', 'shipment');
start.defineDone();
declare hash trans();
trans.defineKey('start_loc', 'start_time');
trans.defineData('start_loc', 'start_time', 'end_loc', 'end_time', 'shipment');
trans.defineDone();
/* Load each transaction into one of the two hash tables. */
/* If it's a starting transaction, add to START. */
/* Otherwise, add to TRANS. */
do while (^done);
set transactions end=done;
if missing(start_loc) then start.add();
else trans.add();
end;
/* Iterate through START, finding a path through TRANS and building an output */
/* data set that contains transactions with a path ID. */
declare hiter startIter('start');
id = 1;
rc = startIter.first();
do while (rc = 0);
/* Clear the value of the start_loc variable from it's previous value of */
/* loading the hash table or the previous iteration of the do while (rc = 0) */
/* loop */
call missing(start_loc, start_time);
/* Output the first transaction of a path */
output;
/* Search through the TRANS hash table and find all the observations */
/* that are linked by their start_loc and end_loc */
et=end_time;
do while (trans.find(key:end_loc, key:et) = 0);
/* In SAS 9.1, the FIND method may not update properly if the variable */
/* specified in the FIND is also defined as data in the hash table. */
/* The work around for this problem is to use a variable that has not */
/* been defined as data in the hash table to supply the key value. */
et=end_time;
/* Computation on SHIPMENT or some other data could be done in this loop. */
/* Output elements from the TRANS hash table. */
output;
end;
rc = startIter.next();
id = id+1;
end;
stop;
run;
proc print;
format start_time end_time time5.;
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.
start_ Obs start_loc time end_loc end_time shipment id 1 . Albany 5:00 50 1 2 Albany 5:00 Denver 10:00 300 1 3 Denver 10:00 Lansing 12:15 15 1 4 . Atlanta 12:00 1000 2 5 Atlanta 12:00 Tallahassee 13:00 10 2 6 Tallahassee 13:00 Springfield 18:00 38 2 7 Springfield 18:00 Bismarck 20:30 24 2 8 Bismarck 20:30 Helena 23:30 90 2 9 . Denver 12:45 30 3 10 Denver 12:45 Bismarck 15:00 45 3 11 Bismarck 15:00 Lansing 18:00 2 3 12 Lansing 18:00 Springfield 24:00 200 3
For releases prior to SAS 9.1, see Using POINT= to trace 'parent-child' lineage in a data set.
Type: | Sample |
Topic: | SAS Reference ==> DATA Step SAS Reference ==> Component Objects SAS Reference ==> Component Objects ==> hash iterator object |
Date Modified: | 2007-12-14 11:20:20 |
Date Created: | 2005-01-14 12:13:16 |
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 |