Date: Thu, 5 Feb 2004 10:57:25 -0500
Reply-To: "DePuy, Venita" <depuy001@DCRI.DUKE.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "DePuy, Venita" <depuy001@DCRI.DUKE.EDU>
Subject: Re: create a new variable that indicate a change
Content-Type: text/plain
This creates diff as a 0/1 variable for whether a difference exists between
the current line and the previous line. It's missing if the previous line
had a different id.
HTH
Venita
data test;
input id amount @@;
lag_amt = lag(amount);
lag_id = lag(id);
if lag_id ne id then lag_amt = .;
diff = lag_amt - amount;
if diff ne 0 and diff ne . then diff = 1;
drop lag_id lag_amt;
cards;
10001 2000 10001 2000 10001 3000 10002 2500
10002 3000 10003 1000
10003 1000 10003 1000 10003 2000 10003 1000
;
proc print;run;
> ----------
> From: Jesper Nyholm[SMTP:jesper_nyholm@POST.TELE.DK]
> Reply To: Jesper Nyholm
> Sent: Thursday, February 05, 2004 10:35 AM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: create a new variable that indicate a change
>
> /***
> Hi
> Can anybody tell me how to create a new variable that indicate a change
> in amount for every id?
> ***/
> DATA TEST;
> INPUT ID 1-5 AMOUNT 7-11;
> DATALINES;
> 10001 2000
> 10001 2000
> 10001 3000
> 10002 2500
> 10002 3000
> 10003 1000
> 10003 1000
> 10003 1000
> 10003 2000
> 10003 1000
> ;
>
|