Date: Fri, 17 Mar 2000 09:40:37 -0000
Reply-To: Nigel.Pain@SCOTLAND.GOV.UK
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Nigel Pain <Nigel.Pain@SCOTLAND.GOV.UK>
Subject: Re: lag & retain
Content-Type: text/plain; charset="iso-8859-1"
Philippe
Not sure if it will answer your problem, but one thing I would try is
creating temporary lag variables for RAPH and STATE (eg. L_RAPH and
L_STATE). The LAG function returns the value of the variable WHEN THE LAG
FUNCTION WAS LAST CALLED FOR THAT VARIABLE. So try this:
DATA roue.fort;
retain raph state;
set data;
length mvt $12;
l_state=lag(state);
l_raph=lag(raph);
if state=l_state then mvt=0;
else if raph=l_raph then mvt=compress(l_state||"_"||state);
run;
***************************************************
Nigel Pain
Scottish Executive Development Department
Business Support Unit
Victoria Quay
EDINBURGH
EH6 6QQ
UK
Tel +44 131 244 7237
Fax +44 131 244 7281
Mailto:nigel.pain@scotland.gov.uk
Website: http:\www.scotland.gov.uk
-----Original Message-----
From: VITE Philippe [mailto:Philippe.VITE@GEP.FR]
Sent: 17 March 2000 08:49
To: SAS-L@LISTSERV.UGA.EDU
Subject: lag & retain
**********************************************************************
This email has been received from an external party and has been
swept for the presence of computer viruses.
**********************************************************************
Hi everybody,
My pb is the following.
I have n processes in my table, indexed by T (n*T rows).
The state of each process (Raph) is indicated by the variable
'state'.
I want to create a variable movement 'mvt' : each time a raph goes
from one value of state to another value of state, i want mvt to be
oldstate_newstate.
I tried to do this in a data step using RETAIN and LAG. But it does
not work properly.
Here's my programm :
DATA roue.fort;
retain raph state;
set data;
length mvt $12;
if state=lag(state) then mvt=0;
else if raph=lag(raph) then mvt=compress(lag(state)||"_"||state);
run;
The result is that mvt appears to be different from zero at the relevent
times, but i get :
mvt=newstate_newstate instead of oldstate_newstate.
It can be done in 2 datasteps, but I would be ashamed to do so...
Any help would be very appreciated.
Philippe.
> Philippe Vité
> --------------------------------------------------------------------------
> Paribas - Nouvelles Technologies - Méthodes Statistiques
> 5, av Kléber, bureau 584.
> 75016 Paris
> 01 40 67 40 16
> philippe.vite@gep.fr
**********************************************************************
This email and any files transmitted with it are intended solely for
the use of the individual or entity to whom they are addressed.
**********************************************************************