Flag parameter used is as per values of voltage for example if voltage is>240 its 2 and if voltage is < 216 then 1 else 0,but i require the code to find out "freq"which is such that if for time slot 1 voltage is 230 and its flag is 0 then freq is 0,but in next slot if value is in that range>216 and <240 then it shld be 0,and again if in next slot if the value of voltage is 242 then freq shld be 1,then again if it continues in that range then 0,and if next slot if value is less than 216 or in that range then it shld change to 1.
Agreed with Linus, straighforward DATA step programming using a sorted input SAS file will work. A starting point link is provided below -- also, you can use the SEARCH facility at the SAS support http://support.sas.com/ website to locate SAS-hosted documentation and supplemental technical/conference topic-related reference. Within the DATA step area, as Linus mentioned, related SAS statements are RETAIN and using the LAG function, or possibly FIRST. and/or LAST. in your DATA step program. You should also consider adding the SAS PUTLOG statement below periodically (during program development and testing) in order to dump SAS variable value conditions as you discover more about the DATA step programming world:
PUTLOG '>DIAG-nn' / _ALL_; * set nn to unique values to see in your log ;