BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
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





Here with some comments:

data want;
set dados;
by name tp;
retain inittime;
then do; /* initialize at start of a name/tp group */
  inittime = .;
  diff = 0; /* will always be zero at start */
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;
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 */
else diff = 0; /* in all other cases */
drop inittime;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 15 replies
  • 4 in conversation