data a;
input caseID $ Entdat yymmdd10. hoscost $;
format Entdat yymmdd10.;
cards;
260754 1950-3-31 62973.59
277270 1950-12-23 136719.83
277270 1951-2-27 95801.55
277270 1952-5-22 54787.56
277270 1952-10-5 163104.40
280785 1951-2-28 83876.28
280785 1952-6-23 157131.43
run;
proc sort data=a;
by caseID Entdat;
run;
data out;
set a;
by caseID;
retain firstdate Thoscost TNumHos FirCost FirNumHos ConCost ConNumHos;
if first.caseID then firstdate=Entdat;
if Entdat-firstdate<365 then tag=1;else tag=2;
if first.caseID then do;
Thoscost=0;
TNumHos=0;
FirCost=0;
FirNumHos=0;
ConCost=0;
ConNumHos=0;
end;
Thoscost+hoscost;
TNumHos+1;
if tag=1 then do;
FirCost+hoscost;
FirNumHos+1;
end;
if tag=2 then do;
ConCost+hoscost;
ConNumHos+1;
end;
if last.caseID;
keep caseID Thoscost TNumHos FirCost FirNumHos ConCost ConNumHos;
run;