This should scale for you now:
data have;
input ID Type $ DIS $ Timepoint Answer_1 Answer_2 Payment;
datalines;
1001 0to5 A 0 0 1 100
1001 0to5 A 1 1 0 210
1001 0to5 A 3 1 . 340
1002 0to5 A 0 1 0 290
1002 0to5 A 1 . 1 180
1003 0to5 B 0 1 1 200
1003 0to5 B 2 . 0 150
1004 6to9 A 0 . . 300
1004 6to9 A 1 1 1 100
1004 6to9 A 2 1 . 340
1005 6to9 A 0 1 1 900
1005 6to9 A 1 0 1 100
1005 6to9 A 3 . 0 940
1006 6to9 A 0 1 . 400
1006 6to9 A 1 1 1 450
;
proc sort data=have;
by TYPE DIS ID;
run;
data have_expanded;
set have;
by type DIS ID;
first_id = first.id;
array pmt_ans(2);
array answer(2) answer_1-answer_2;
do i=1 to dim(answer);
if nmiss(answer(i), payment) = 0 then pmt_ans(i) = payment;
end;
run;
proc means data=have_expanded nway noprint;
by type dis;
var pmt_ans: ;
output out=want sum(first_id) = Num_IDs median = / autoname;
run;
... View more