User:Statcompute/BlogEntry: 2007 April 22 21:11:54 EDT

From sasCommunity

Jump to: navigation, search
/************************************************
* USE NEXT METHOD OF HITER OBJECT TO ACCESS THE *
* NEXT RECORD IN THE COLUMN                     *
************************************************/

data one;
  do x = 1 to 10;
    output;
  end;
run;

data _null_;

  if _n_ = 1 then do;
    declare hash h (dataset: 'one', hashexp: 4, ordered: 'a');
    h.definekey ('x');
    h.definedata ('x');
    h.definedone();
    declare hiter iter('h');
  end;

  do rc = iter.next() by 0 while (rc = 0);
    set one;
      current = x;
      /* KEY STEP: MOVE TO NEXT RECORD */
      rc = iter.next();
      next = x;
      if rc = 0 then do;
        put ' CURRENT RECORD = ' current ' NEXT RECORD =' next;
      end;
  end;
run;
Personal tools