Date: Mon, 18 Aug 2008 13:41:49 -0500
Reply-To: Mary <mlhoward@avalon.net>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Mary <mlhoward@AVALON.NET>
Subject: Re: how to copy a row
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
reply-type=original
Here's one more solution- this one also "backwards fills"- so that if you
have a missing in the first visit in a patient the value from the next or
subsequent visit is used as its value; I forward fill, then sort it in order
by visit backwards, the apply the fill again, note this gives adm in the
first visit for patid 1 a 25, since it is the next available value, but the
missing for adm in patid3 visit 1 stays missing since it is the only visit.
data test;
infile cards missover;
input patid visit adm dose wt;
obsnum + 1;
cards;
001 1 . 32 78
001 2 25 54 78
001 3 . . .
002 1 56 54 90
002 2 60 56 .
003 1 . 55 88
;
proc sort data=test;
by patid visit;
run;
data test2;
set test;
by patid;
array vararray{3} adm dose wt;
do i=1 to 3;
a=lag(vararray(i));
if vararray(i)=. and not first.patid then vararray(i)=a;
end;
drop i a;
run;
proc sort data=test2;
by patid descending visit;
run;
data test3;
set test2;
by patid;
array vararray{3} adm dose wt;
do i=1 to 3;
a=lag(vararray(i));
if vararray(i)=. and not first.patid then vararray(i)=a;
end;
drop i a;
run;
proc sort data=test3;
by patid visit;
run;
----- Original Message -----
From: pausha
To: SAS-L@LISTSERV.UGA.EDU
Sent: Monday, August 18, 2008 10:50 AM
Subject: how to copy a row
i have this strangle condition and need some help
I have a dataset with patients who visit every week ,say if they miss
a week i still have to have their data copied form previous week for
that missed one.
eg
pat-id visit adm dose wt
001 1 52 32 78
001 2 25 54 78
001 3 . . .
002 1 56 54 90
002 2 . . .
in this case i would have to have the previous row copied to the
visits that is missing
help with logic to populate the whole row
i have 40 variables in a row.
thanks