/***************************************************************************************************************** SAS file name: Do_Over_Example File location: _________________________________________________________________________________________________________________ Purpose: To demonstrate how to lookup multiple values for a given key with the Do_Over hash object method Author: Peter Clemmensen Creation Date: 18/03/2018 This program supports the example page "SAS Hash Object Do_Over Method Example" on SASnrd.com *****************************************************************************************************************/ /* Example Data */ data Customers; input CustID $ @@; datalines; 112 113 114 ; data Transactions; input CustID $ Quantity; datalines; 111 20 111 40 112 10 112 50 112 10 113 60 113 20 114 50 114 30 114 50 114 30 114 40 115 90 115 70 ; /* Find/Find_Next Method */ data FindFindNext(drop=rc); if 0 then set Transactions; if _N_=1 then do; declare hash h(dataset:"Transactions", multidata:"Y"); h.definekey("CustID"); h.definedata("Quantity"); h.definedone(); end; set Customers; do rc=h.find() by 0 while (rc=0); output; rc=h.find_next(); end; run; /* Do_Over Method */ data Do_Over; if 0 then set Transactions; if _N_=1 then do; declare hash h(dataset:"Transactions", multidata:"Y"); h.definekey("CustID"); h.definedata("Quantity"); h.definedone(); end; set Customers; do while (h.do_over()=0); output; end; run;