Date: Wed, 14 May 2008 15:06:31 -0500
Reply-To: "data _null_," <datanull@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "data _null_," <datanull@GMAIL.COM>
Subject: Re: How to generate a delta variable in longitudinal data
In-Reply-To: <98634D42B37B2E4E96CF3A3BD3CD9AE60182ABC2@EX1VS2.nyced.org>
Content-Type: text/plain; charset=ISO-8859-1
This variation deals with the lack of baseline issue. Computation of
baseline sometimes involves more than one pre-event value which is not
address here.
data long;
input id:$1. Time Var1;
cards;
1 0 10
1 10 12
1 20 11
1 30 17
2 10 12
2 20 11
2 30 17
3 0 17
3 10 12
3 20 11
3 30 17
;;;;
run;
data long;
do until(last.id);
set long;
by id;
if time eq 0 then baseline=var1;
if n(baseline,var1) eq 2 then delta = var1 - baseline;
output;
end;
run;
proc print;
run;
On 5/14/08, Bucher Scott <SBucher@schools.nyc.gov> wrote:
> Hi Jane,
>
> The easiest way may be to transpose the data by time and then calculate
> the differences. Another method is as follows, but this will have
> unexpected results if your data deviates from the example data (e.g. an
> id lack a basline value).
>
> data dsn;
> input
> Id Time Var1;
> datalines;
> 1 0 10
> 1 10 12
> 1 20 11
> 1 30 17
> ;
>
> Proc sort data = dsn;
> By id time;
> Run;
>
> Data dsn;
> Set dsn;
> Retain baseline;
> By id;
> If first.id = 1 then do;
> Baseline = var1;
> End;
> Delta = var1 - baseline;
> Run;
>
> Regards,
> Scott
>
> -----Original Message-----
> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of jn
> mao
> Sent: Wednesday, May 14, 2008 3:05 PM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: How to generate a delta variable in longitudinal data
>
> Hello SAS-Ls,
>
> I have a longitudinal data file. There are 10 time points, I need to
> generate a new variable that is the difference of the value of the old
> variable between each time point and the baseline time point. How do I
> generate it?
>
> The original data format:
> Id Time Var1
> 1 0 10
> 1 10 12
> 1 20 11
> 1 30 17
>
> The data I want:
> Id Time Var1 Delta1
> 1 0 10 0 (10-10)
> 1 10 12 2 (12-10)
> 1 20 11 1 (11-10)
> 1 30 17 7 (17-10)
>
> Could someone help me on SAS code for generating Delta1? Thanks much!
>
> Jane
>
|