Even though I feel this can be done using one-step Hash, but the easier way for me is to generate a intermediate table to first categorize the data, then apply some data step DOW. data have; input date :mmddyy10. response ; format date mmddyy10.; cards; 1/1/2010 5 1/2/2010 5 1/3/2010 9 1/4/2010 5 1/5/2010 5 1/6/2010 9 1/7/2010 9 1/8/2010 9 1/9/2010 9.5 1/10/2010 9.5 1/11/2010 9 1/12/2010 9 1/13/2010 7 1/14/2010 6 1/15/2010 5 ;;;; proc format; value res low -< 9 = 'low' 9 - high ='high' ; run; data want1; set have; _cat=put(response, res4.); run; data want; do _n_=1 by 1 until (last._cat); set want1; by _cat notsorted; end; do _i=1 by 1 until (last._cat); set want1; by _cat notsorted; if _cat='high' and _n_>=7 and _i=1 then flag=1;else flag=.; output; end; drop _:; run; Haikuo Update: FWIW, Here is a Hash solution: data want_hash; if _n_=1 then do; declare hash h(ordered:'y'); h.definekey('date'); h.definedata('date','response'); h.definedone(); declare hiter hi('h'); end; set have ; if response <9 then do; _d=date;_r=response; rc=hi.first(); do _i=1 by 1 while (rc = 0); if h.num_items >=7 and _i=1 then flag=1; else flag=.; output; rc=hi.next(); end; h.clear(); date=_d;response=_r;output; end; else h.replace(); keep date response flag; run;
... View more