From: Al on
Dear All:

Below is the sample data i have ...


pat vis res
1 BL 12
1 BL 13
1 wk1 14
1 wk2 13
1 wk3 14
2 BL 10
2 wk1 11
2 wk2 12
2 wk3 11

and below is the data i am trying to generate by
creating two variable avg and cfb where
avg = average of all values per pat and vis ,
cfb = ((avg at a vis -- avg at BL )/avg at BL )*100

pat vis res avg % cfb
1 BL 12 12.5 0
1 BL 13 12.5 0
1 wk1 14 13.67 9.36
1 wk2 13 13.67 9.36
1 wk3 14 13.67 9.36
2 BL 10 10 0
2 wk1 11 11.3 13
2 wk2 12 11.3 13
2 wk3 11 11.3 13


Thanks in advance
Al

From: smileguy on
On Jun 16, 9:22 am, Al <ali6...(a)gmail.com> wrote:
> Dear All:
>
> Below is the sample data i have ...
>
>   pat vis  res
>   1   BL    12
>   1   BL    13
>   1   wk1   14
>   1   wk2   13
>   1   wk3   14
>   2   BL    10
>   2   wk1   11
>   2   wk2   12
>   2   wk3   11
>
> and below is the data  i am trying to generate by
> creating two variable avg and cfb where
> avg = average of all values per pat and vis ,
> cfb = ((avg at a vis -- avg at BL )/avg at BL )*100
>
>   pat vis  res avg   % cfb
>   1   BL    12 12.5    0
>   1   BL    13 12.5    0
>   1   wk1   14 13.67   9.36
>   1   wk2   13 13.67   9.36
>   1   wk3   14 13.67   9.36
>   2   BL    10 10      0
>   2   wk1   11 11.3    13
>   2   wk2   12 11.3    13
>   2   wk3   11 11.3    13
>
>   Thanks in advance
>   Al

data test;
input pat vis $ res;
cards;
1 BL 12
1 BL 13
1 wk1 14
1 wk2 13
1 wk3 14
2 BL 10
2 wk1 11
2 wk2 12
2 wk3 11
;
run;

proc sql;
create table test1 as
select test.*,mean(res)as avg,(mean(res)-avgbl)*100/avgbl as CFB
label='% cfb'
from
test A ,
(select pat,mean(res) as avgbl from test
where vis='BL'
group by pat,vis) B
where A.pat=b.pat
group by A.pat,substr(vis,1,2);
quit;