Date: Wed, 3 Jun 2009 23:25:02 -0400
Reply-To: Ya Huang <ya.huang@AMYLIN.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Ya Huang <ya.huang@AMYLIN.COM>
Subject: Re: merge
This can be done with a single sql step:
proc sql;
select *,monotonic() as origord, var(weig) as variance
from ani
group by treat,type
order by origord
;
id treat age weig type origord variance
--------------------------------------------------------
1 TA 333 365 P1201 1 924.5
1 TA 453 603 P1801 2 12.5
319 TA 236 408 P1201 3 924.5
319 TA 345 608 P1801 4 12.5
1 TS 300 355 P1201 5 32
1 TS 441 593 P1801 6 2738
318 TS 233 347 P1201 7 32
318 TS 264 519 P1801 8 2738
3 NI 299 393 P1201 9 480.5
3 NI 362 589 P1801 10 840.5
451 NI 220 362 P1201 11 480.5
451 NI 276 548 P1801 12 840.5
On Wed, 3 Jun 2009 19:45:59 -0700, Bobs <fabianezte@GMAIL.COM> wrote:
>Hello,
>
>I have longitudinal data in long form (shown below), small example.
>I calculate the variance for each Weig by type into of each treat.
>Now, I want to make the merge to concatenate each value of variance of
>each Weig by
>id (subject) inside the treat, or I create a new column in the file so
>that id have the value of the variance for each corresponding Weig.
>
>data ani;
>input id treat $ age weig type $;
>datalines;
>1 TA 333 365 P1201
>1 TA 453 603 P1801
>319 TA 236 408 P1201
>319 TA 345 608 P1801
>1 TS 300 355 P1201
>1 TS 441 593 P1801
>318 TS 233 347 P1201
>318 TS 264 519 P1801
>3 NI 299 393 P1201
>3 NI 362 589 P1801
>451 NI 220 362 P1201
>451 NI 276 548 P1801
>;
>proc print;run;
>
>proc sort data=ani out=weight_1;
>by treat type;
>run;
>proc print data=weight_1;run;
>
>proc means data=weight_1 var;
>class treat type;
>var weig;
>run;
>
>my database has to be as shown below
>
>data ani;
>input animal treat $ age weig type $ variance;
>datalines;
>1 TA 333 365 P1201 924.5000000
>1 TA 453 603 P1801 12.5000000
>319 TA 236 408 P1201 924.5000000
>319 TA 345 608 P1801 12.5000000
>1 TS 300 355 P1201 32.0000000
>1 TS 441 593 P1801 2738.00
>318 TS 233 347 P1201 32.0000000
>318 TS 264 519 P1801 2738.00
>3 NI 299 393 P1201 480.5000000
>3 NI 362 589 P1801 840.5000000
>451 NI 220 362 P1201 480.5000000
>451 NI 276 548 P1801 840.5000000
>; proc print;run;
>
>Anyone have a idea.
>Thank you in advance,
|