Ok. Thank you all answers, seriously. I think the solutions are not what i want. I will be more specific: My data in a dataset that i have to try the code data work.dados(label='Dados');
infile datalines dsd truncover;
input Time:32. Name:$8. Tp:$1. Age:$3. Type:$2.;
datalines4;
107,Joyce,B,OFF,Dj 110,Joyce,B,OFF,Dj
202,Jane,C,OFF,Dj
304,Alice,A,ON,Pr
476,Alice,A,OFF,Dj
546,Barbara,D,OFF,Dj
628,Carol,F,OFF,Dj
756,Mary,G,ON,Pr
858,Mary,F,ON,Pr
929,Mary,G,OFF,Dj
949,Thomas,I,ON,Pr
989,Thomas,I,OFF,Dj
1002,Jane,C,ON,Pr
1006,Jane,C,ON,Pr
1010,Jane,Z,ON,Pr
1100,Jane,C,OFF,Dj
1235,Thomas,A,ON,Pr
1240,Thomas,I,ON,Pr
1304,Thomas,I,OFF,Dj
;;;; The idea is calculate time difference between same "Name" with same "Tp" and OFF Dj -> ON Pr (first in time(older), not second in time(newer)). Attention Thomas has two calculations. And for example Joyce don't have correspond ON Pr in the table, so not need to calculate difference. Or for example Carol is only one observation, no need to calculate difference. I can not use the names because could be hundreds of them xD. That why i try to do two do while statements to find all names needed. I know that It is very difficult to be efficient to do this. Want
107,Joyce,B,OFF,Dj,0 110,Joyce,B,OFF,Dj,0
202,Jane,C,OFF,Dj,0
304,Alice,A,ON,Pr,0
476,Alice,A,OFF,Dj,172
546,Barbara,D,OFF,Dj,0
628,Carol,F,OFF,Dj,0
756,Mary,G,ON,Pr,0
858,Mary,F,ON,Pr,0
929,Mary,G,OFF,Dj,173
949,Thomas,I,ON,Pr,0
989,Thomas,I,OFF,Dj,40
1002,Jane,C,ON,Pr,0
1006,Jane,C,ON,Pr,0
1010,Jane,Z,ON,Pr,0
1100,Jane,C,OFF,Dj,98
1235,Thomas,A,ON,Pr,0
1240,Thomas,I,ON,Pr,0
1304,Thomas,I,OFF,Dj,64 If i understand how to code this work i will be happy and will improve my programming skills to a next level. Sorry my last posts but to study programming we have to do work step by step, simple to complicated to achieve our final goal. Regards, Aleixo
... View more