title: Invalid DO loop control information in SAS Base
body: <p>I need to find for every row the last 3hr usage (Usage is one of the columns in dataset) grouped by User and ID_option. 
  Every line(row) represent one record (within 3 min time interval). For example (including desired column sum_usage_3hr):</p>
  
  <pre><code>User  ID_option          time             usage        sum_usage_3hr
  1         a1        12OCT2017:11:20:32       3             10
  1         a1        12OCT2017:10:23:24       7             14
  1         b1        12OCT2017:09:34:55       12            12
  2         b1        12OCT2017:08:55:06       4              6
  1         a1        12OCT2017:07:59:53       7              7
  2         b1        12OCT2017:06:59:12       2              2
  </code></pre>
  
  <p>I have used code below for hash table:</p>
  
  <pre><code>data want;
   if _n_=1 then do;
    if 0 then set have(rename=(usage=_usage));
    declare hash h(dataset:'have(rename=(usage=_usage))',hashexp:20);
    h.definekey('user','id_option','time');
    h.definedata('_usage');
    h.definedone();
   end;
  set have;
  sum_usage_3hr=0;
  do i=time-3*3600 to time ;
   if h.find(key:user,key:id_option,key:i)=0 then sum_usage_3hr+_usage;
  end;
  drop _usage i;
  run;
  </code></pre>
  
  <p>But I got an error: Invalid DO loop control information, either the INITIAL or TO expression is missing or the BY expression is missing, zero, or invalid. If I add:
  output;
  end:
  just above the "run;" it gives me an error: 'No matching DO/Select statement'.
  Anybody know what causes the problem? 
  I have also the version with sorting the table firstly and gives me the same error. 
  Thank you</p>
  
  <p>After implementing the for answer:</p>
  
  <pre><code>User  ID_option          time             usage   sum_usage_3hr   col_i_got
  1         a1        12OCT2017:11:22:32       3         12             3      
  1         a1        12OCT2017:11:20:24       0          9             3
  1         a1        12OCT2017:10:34:55       2          9             2
  1         a1        12OCT2017:09:55:06       0          7             2
  1         a1        12OCT2017:09:43:45       0          7             0
  1         a1        12OCT2017:08:59:53       7          7             7
  1         a1        12OCT2017:06:59:12       0          0             7
  </code></pre>