As featured in: Data Management Solutions Using SAS Hash Table Operations: A Business Intelligence Case Study , and built from this github repository.
Chapter 10 Implementing a Hash Queue.sas
1 /* "Chapter 10 Implementing a Hash Queue.sas" from the SAS Press book
2  Data Management Solutions Using SAS Hash Table Operations:
3  A Business Intelligence Case Study
4 */
5 
6 data Demo_Queue (keep = Action PDV_Data Items) ;
7  dcl hash h (ordered:"A") ;
8  h.defineKey ("Key") ;
9  h.defineData ("Key", "Data") ;
10  h.definedone () ;
11  dcl hiter ih ("h") ;
12  Data = "A" ; link Queue ;
13  Data = "B" ; link Queue ;
14  Data = "C" ; link Queue ;
15  link DeQueue ;
16  Data = "D" ; link Queue ;
17  Data = "E" ; link Queue ;
18  link DeQueue ;
19  link DeQueue ;
20  stop ;
21  Queue: Key + 1 ;
22  h.add() ;
23  Action = "Queue " ;
24  link List ;
25  return ;
26  DeQueue: ih.first() ;
27  rc = ih.prev() ;
28  h.remove() ;
29  Action = "DeQueue" ;
30  link List ;
31  return ;
32  List: PDV_Data = Data ;
33  Items = put ("", $64.) ;
34  do while (ih.next() = 0) ;
35  Items = catx (" ", Items, cats ("[", Key, ",", Data, "]")) ;
36  end ;
37  output ;
38  return ;
39 run ;