BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kurt_Bremser
Super User

@Aleixo wrote:

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 15 replies
  • 3430 views
  • 4 likes
  • 4 in conversation