WoW, It's amazing what you have done. So simple what you do, i am delighted. Worked very well.
I will try to understand how it really works the code and the loop. Thank you so much
Regards,
Aleixo
Here with some comments:
data want;
set dados;
by name tp;
retain inittime;
if first.tp
then do; /* initialize at start of a name/tp group */
inittime = .;
diff = 0; /* will always be zero at start */
end;
if age = 'ON' and inittime = .
then do; /* this is the first occurence after a start of group or OFF event */
inittime = time; /* this also prevents the detection of an immediately following ON event */
diff = 0;
end;
else if age = 'OFF' and inittime ne .
then do; /* this detects the change to OFF, but only when there wasn't one already */
diff = time - inittime;
inittime = .; /* prevents setting of diff = 0 for an immediately following OFF event */
end;
else diff = 0; /* in all other cases */
drop inittime;
run;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!