Update current record with next record value (1 Viewer)

Ben_Entrew

Registered User.
Local time
Yesterday, 20:28
Joined
Dec 3, 2013
Messages
177
Hi all,

I want to identify the time frame of a agent's job.
For example Agent 081 had a task aaa from 202012-202104, then it switched to task vvv from 202104 until now 202102.

I found this code:

data want;
recno=_n_+1;
set Task_times end=last;
if not last


then set Task_times (keep=TIME_ID rename=(TIME_ID=TO)) point=recno;
else call missing(TO);
run;


The output looks like:

TIME_IDAgentA_typeFROMTO
202012​
081aaa
202012​
202104​
202104​
081vvv
202104​
202012​
202012​
082aaa
202012​
202102​
202102​
082vvv
202102​
202102​
202102​
083aaa
202102​
202112​
202112​
083vvv
202112​
202012​

It's not exactly what I want, I need to check also the Agents.

Does anyone know how I can add an additional condition checking wheter the Agent of the next row is the same or not?

Thank you.

Many greetings,
Ben
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 11:28
Joined
May 7, 2009
Messages
19,228
See Query1.
 

Attachments

  • TimeShift.accdb
    552 KB · Views: 191

Ben_Entrew

Registered User.
Local time
Yesterday, 20:28
Joined
Dec 3, 2013
Messages
177
Many Thanks Arnelgp,

forgot to mention I'm trying this in SAS.
Somehow SELECT TOP 1 doesn't work out here.

Any clue how to adjust this?

Thanks.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 11:28
Joined
May 7, 2009
Messages
19,228
sorry, no idea.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 23:28
Joined
Feb 19, 2002
Messages
43,213
In a relational database, no record is dependent on any other record but you are trying to make that happen. If this data is in YOUR database, then the correct solution is to "close" the open record when a new task is started. That solves the problem and makes the rows independent. If this is someone else's data, then you need a unique identifier on which to sort the rows and the previous ID must be the record you want to close if you can't use the method suggested by arnel.
 

Users who are viewing this thread

Top Bottom