|
hi ... if you sort the data within a child in descending cost order and add a count to each
observation within a child, this works ... use six or fewer observations per child, the six are
always the top six in cost while those with < 6 use all the months ...
data test;
input childid month cost @@;
datalines;
1 1 90 1 3 100 1 5 66 1 8 99 1 9 44 1 10 23 1 12 555
2 2 94 2 7 82 2 12 54
;
run;
proc sort data=test;
by childid descending cost;
run;
data test;
do until (last.childid);
set test;
by childid;
nrecs = sum(nrecs,1);
output;
end;
run;
proc means data=test;
where nrecs le 6;
class childid;
var cost;
run;
--
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,
>
> I have medical cost data on children for some or all months of 2007. A
> simplified sample of the data is given below (month=1=January, etc.) I
> want to calculate the mean montly expense per child. Normally, that would
> be easy with PROC MEANS, but there is a complication: I want the mean only
> over the six months with highest medical costs. If the child has data for
> more than six months, I want to calculate as above, but if the child has
> less than six months of data I'd like to take the average of all the
> monthly data for the child. How might I do this?
>
> Thanks in advance,
>
> Howard Alper
>
>
>
> data homedir.test;
> input childid month cost;
> datalines;
> 1 1 90
> 1 3 100
> 1 5 66
> 1 8 99
> 1 9 44
> 1 10 23
> 1 12 555
> 2 2 94
> 2 7 82
> 2 12 54
> ;
> run;
>
>
|