LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (June 2004, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 29 Jun 2004 22:33:03 +0200
Reply-To:   Datametric <datametric@CLUB-INTERNET.FR>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Datametric <datametric@CLUB-INTERNET.FR>
Subject:   RE : Lag Question
Comments:   To: "Dunn, Toby" <tdunn@TEA.STATE.TX.US>
In-Reply-To:   <748343794E05734F9D9E9BBF2CA6D2140DB9B3@LYNDON.tea.state.tx.us>
Content-Type:   text/plain; charset="iso-8859-1"

Hi,

I use

data ccc; set one; z = lag(x); if z = . then z = x; run;

Instead of :

data ccc; set one; z = lag(x); if z = . then z = x; if z=. then z= 99; run;

And I get :

Obs x y z

1 1 a 1 2 2 a 1 3 . a 2 4 4 a 4 5 1 b 4 6 . b 1 7 . b 99 8 1 c 1 9 2 c 1 10 1 d 2

Is that you want ?

Stéphane.

-----Message d'origine----- De : SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] De la part de Dunn, Toby Envoyé : mardi 29 juin 2004 22:15 À : SAS-L@LISTSERV.UGA.EDU Objet : Lag Question

I am working a paper and have worked myself into question.

Say you have the following dataset:

data one;

input x y $1.;

cards;

1 a

2 a

.. a

4 a

1 b

.. b

.. b

1 c

2 c

1 d

;

run;

and want to use the lag function to lag the value of variable (X) when ever it is missing:

Easiest I figure is the following.

data ccc;

set one;

z = lag(x);

if x = . then x = z;

run;

However, it gives a value of missing when there are two missing values of x in a row:

Obs x y z

1 1 a .

2 2 a 1

3 2 a 2

4 4 a .

5 1 b 4

6 1 b 1

7 . b .

8 1 c .

9 2 c 1

10 1 d 2

Makes since, given how the queue works when using the Lag Function. Now how would one use the Lag function and come up with value for the above missing value and a value if there were more than one missing value for x in a row?

For the life of me I can't come up with a workable solution if all I have is the LAG function.

TIA

Toby Dunn


Back to: Top of message | Previous page | Main SAS-L page