@Demoxe: Sorry, but your data step is just very difficult to read and probably incorrect.
Based on the variable names, I guess what you are trying to do is to calculate total cost of phone calls for each subscriber (abonent). The price of a phone call is calculated by multiplying the callTime and price. The price seems to be determined by the value of id_tarif, which in turn decided by the abonent and the date range within which the call date falls into. If this is a correct guess, then it is quite easy to do.
In the below, the total cost for the abonent 10 is 230, because abonent 10's first phone call is made on the date 17103, which is between 17000 and 17199, during which the tarif was 7 thus the price was 5, while the three remaining calls are made during the dates when the tarif was 1 thus the price was 5. Total cost thus was: 1*5 + 9*9 + 8*9 + 8*9 = 230.
[pre]
/* test data */
data tarifs;
input id_tarif price;
cards;
1 9
2 8
3 10
4 6
5 3
6 7
7 5
8 4
9 5
10 7
;
run;
data abonents;
input id_abonent id_tarif date_begin date_end;
cards;
1 7 17000 17200
1 2 17201 17400
2 9 17000 17200
2 8 17201 17400
3 3 17000 17200
3 10 17201 17400
4 10 17000 17200
4 9 17201 17400
5 1 17000 17200
5 3 17201 17400
6 8 17000 17200
6 10 17201 17400
7 8 17000 17200
7 2 17201 17400
8 10 17000 17200
8 3 17201 17400
9 10 17000 17200
9 7 17201 17400
10 7 17000 17200
10 1 17201 17400
;
run;
data calls;
input id_abonent dateCall timeCall;
cards;
2 17099 8
2 17111 5
2 17175 9
3 17019 4
3 17130 3
3 17215 6
3 17268 10
4 17119 5
5 17038 1
5 17095 5
6 17064 7
6 17201 6
6 17298 8
7 17014 3
7 17057 3
7 17148 4
7 17199 8
8 17079 9
8 17134 4
8 17206 2
9 17210 10
10 17103 1
10 17217 9
10 17217 8
10 17247 8
;
run;
proc sql;
/* attach price to abonents matching tarifs */
create view prices as
select a.*, t.price
from abonents as a left join tarifs as t
on a.id_tarif=t.id_tarif;
/* calc the cost of each call looking up the tarif (and thus the price)
based on the call date and multiplying the price with the call time.
assumes that there are no call dates that match multiple date ranges */
create view costs as
select c.*, c.timeCall*p.price as cost
from calls as c left join prices as p
on c.id_abonent=p.id_abonent and
p.date_begin <= c.dateCall and c.dateCall < p.date_end;
/* calculate total cost for each abonent */
create table totals as
select id_abonent
, count(*) as num_calls
, min(dateCall) as date_from
, max(dateCall) as date_to
, sum(cost) as total_cost
from costs
group by id_abonent
order by id_abonent;
/* check */
select * from totals;
quit;
/* on lst
id_abonent num_calls date_from date_to total_cost
------------------------------------------------------
2 3 17099 17175 110
3 4 17019 17268 182
4 1 17119 17119 35
5 2 17038 17095 54
6 3 17064 17298 126
7 4 17014 17199 72
8 3 17079 17206 111
9 1 17210 17210 50
10 4 17103 17247 230
*/
[/pre]