Date: Wed, 24 Mar 2010 15:24:53 -0400
Reply-To: msz03@albany.edu
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Mike Zdeb <msz03@ALBANY.EDU>
Subject: Re: How to calculate difference with longitudinal data format
Content-Type: text/plain;charset=iso-8859-1
hi ... this will produce what you showed, but it's not that "generic" in that
if you have a lot more data, what's it look like and what are the rules for
pairing up the data so you can compute differences
if it's just a lot more days with groups a and b defining how to compute differences,
this will still work
data old;
input id day group : $1. var1;
datalines;
1 1 a 12
1 2 a 16
1 3 a 11
2 1 b 9
2 2 b 10
2 3 b 11
;
run;
data diff;
length group $3.;
merge
old (where=(g1 eq 'a') rename=(var1=v1 group=g1) drop=id)
old (where=(g2 eq 'b') rename=(var1=v2 group=g2) drop=id)
;
by day;
diff = catt(v1-v2,'(',v1,'-',v2,')');
group = catx('-',g1,g2);
id+1;
keep id day group diff;
run;
proc print data=diff;
var id day group diff;
run;
OUTPUT ...
id day group diff
1 1 a-b 3(12-9)
2 2 a-b 6(16-10)
3 3 a-b 0(11-11)
--
Mike Zdeb
U@Albany School of Public Health
One University Place
Rensselaer, New York 12144-3456
P/518-402-6479 F/630-604-1475
> Hi SAS-Ls,
>
> I have a longitudinal dataset, and I need to calculate the delta between groups. How can I code it?
>
> old data
> id day group var1
> 1 1 a 12
> 1 2 a 16
> 1 3 a 11
> 2 1 b 9
> 2 2 b 10
> 2 3 b 11
>
> data I want:
> id day group diff
>
> 1 1 a-b 3(12-9)
>
> 2 2 a-b 6(16-10)
>
> 3 3 a-b 0(11-11)
>
> Thanks a lot.
> Jane
>
>
>
>
>
>
>