Date: Fri, 17 Mar 2000 12:03:13 +0100
Reply-To: VITE Philippe <Philippe.VITE@GEP.FR>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: VITE Philippe <Philippe.VITE@GEP.FR>
Subject: Re: lag & retain
Content-Type: text/plain; charset="iso-8859-1"
Hear this.
I looked again at your code. The little difference i noticed was ;
retain raph state;
vs my
retain state raph;
So i switch the variables in the order you used... and it works !!!!
Thank you very much for your help. You were right to insist...
Philippe
ps : The thing is I still don't really understand how retain and lag do
work !
> ----------
> De : Nigel Pain[SMTP:Nigel.Pain@SCOTLAND.GOV.UK]
> Répondre à : Nigel.Pain@SCOTLAND.GOV.UK
> Date : 17. marsta 2000 11:04
> A : SAS-L@LISTSERV.UGA.EDU
> Objet : Re: lag & retain
>
> That puzzles me. I tried it with some test data and it worked - 6.12 on NT
> 4.0. See below:
>
> LOG:
>
> 73 data work.premier;
> 74 length raph state $ 1;
> 75 infile datalines;
> 76 input raph state;
> 77 datalines;
>
> NOTE: The data set WORK.PREMIER has 5 observations and 2 variables.
> NOTE: The DATA statement used 0.28 seconds.
>
>
> 83 ;
> 84 run;
> 85
> 86
> 87
> 88 DATA work.seconde;
> 89 retain raph state;
> 90 drop l_state l_raph;
> 91 set premier;
> 92 length mvt $12;
> 93 l_state=lag(state);
> 94 l_raph=lag(raph);
> 95 if state=l_state then mvt=0;
> 96 else if raph=l_raph then mvt=compress(l_state||"_"||state);
> 97 run;
>
> NOTE: Numeric values have been converted to character values at the places
> given by: (Line):(Column).
> 95:31
> NOTE: The data set WORK.SECONDE has 5 observations and 3 variables.
> NOTE: The DATA statement used 0.28 seconds.
>
>
> 98
> 99 proc print;
> 100 run;
>
> NOTE: The PROCEDURE PRINT used 0.44 seconds.
>
> OUTPUT:
>
> OBS RAPH STATE MVT
>
> 1 a 1
> 2 a 1 0
> 3 a 2 1_2
> 4 b 2 0
> 5 b 1 2_1
>
> ***************************************************
> 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 09:51
> To: SAS-L@LISTSERV.UGA.EDU; Nigel.Pain@scotland.gov.uk
> Subject: RE: lag & retain
>
>
>
> **********************************************************************
> This email has been received from an external party and has been
> swept for the presence of computer viruses.
> **********************************************************************
>
> Nigel,
>
> That was my first idea too (I wrote exactly the same code !!), but
> the thing is that the pb remains the same, i.e. I always get :
> newstate_newstate instead of what i expect.
>
> ???#!!!
>
> I must say I found it very curious, as often when using lag &
> retain...
>
> Thanks for your help
>
> > ----------
> > De : Nigel Pain[SMTP:Nigel.Pain@SCOTLAND.GOV.UK]
> > Répondre à : Nigel.Pain@SCOTLAND.GOV.UK
> > Date : 17. marsta 2000 10:40
> > A : SAS-L@LISTSERV.UGA.EDU
> > Objet : Re: lag & retain
> >
> > 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.
> > **********************************************************************
> >
>
> **********************************************************************
> This email and any files transmitted with it are intended solely for
> the use of the individual or entity to whom they are addressed.
> **********************************************************************
>
|