Date: Tue, 31 Jul 2007 07:30:09 -0000
Reply-To: Pralay <pralayhazra@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Pralay <pralayhazra@GMAIL.COM>
Organization: http://groups.google.com
Subject: Re: Help computing a duration from complex data
In-Reply-To: <1185840241.998459.7860@d55g2000hsg.googlegroups.com>
Content-Type: text/plain; charset="us-ascii"
On Jul 31, 5:04 am, pagabas <paga...@yahoo.com> wrote:
> Hi,
>
> I want to compute a duration for each of our machines in the shop.
> Attached is just an example to illustrate the sitution:
> The duration should be calculated when the status goes from MAOFF to
> MAON. Therefore we should only look for
> successive status of MAOFF and MAON. If we encounter an MAOFF and
> subsequent records for that Machine are MAOFF and then an MAON, we
> should compute the duration using the first MAOFF and the last MAON.
> If the machine has all MAOFF or MAON, then there is no need to compute
> a duration. Those cases can be flagged (preferably) or discarded. The
> key is that it must go from MAOFF to MAON state to have a duration.
>
> Using the data below:
>
> MachineID Duration (in sec):
> 100 120
> 100 240
> 101 130
>
> MachineID Status datetimeinfo
> 100 MAOFF 29Jul200710:50:51
> 100 MAON 29Jul200710:52:51
> 100 MAOFF 29Jul200710:55:00
> 100 MAON 29Jul200710:59:00
> 101 MAON 29Jul200710:50:00
> 101 MAON 29Jul200710:52:00
> 101 MAOFF 29Jul200710:53:00
> 101 MAON 29Jul200710:55:10
> 102 MAON 29Jul200711:57:00
> 102 MAON 29Jul200710:57:18
> 102 MAOFF 29Jul200710:57:00
>
> Thanks,
> Pagabas
Hello Pagabas,
You can try out this following code.
data machine;
set machine;
retain prev_value prev_machine_id;
if status="MAOFF" then do;
prev_value=DateTimeInfo;
prev_machine_id=MachineID;
end;
if status="MAON" and MachineID=prev_machine_id then dur=DateTimeInfo
- prev_value;
run;
Let me know if you find any problem with the code.
Cheers,
Pralay
|