I re-read your latest reply ... and note that you probably did run into this
problem the first time you used UNIQUE ... since you only got one record read
from CALLS.
Anyway I re-worked your original code, in order to RETAIN the values on ABONENTS
that are used for the matching criteria ... and so that after the first match in
CALLS is done the remaining records in CALLS are first compared to the last
matching ABONENTS record ... and then goes through ABONENTS if no match is found
... etc.
Here's the code:
data timecost (drop=datebegin dateend id_abonents
rename=(id_calls=id_abonent));
retain Total_Cost 0 datebegin dateend id_abonents;
set calls (rename=(id_abonent=id_calls))
end=last;
if _n_ eq 1 then set abonents (rename=(id_abonent=id_abonents
date_begin=datebegin
date_end=dateend));
else;
if (not((id_calls=id_abonents) and (datebegin<=dateCall<dateend)))
then
do until ((id_calls=id_abonents) and (datebegin<=dateCall<dateend));
set abonents (rename=(id_abonent=id_abonents
date_begin=datebegin
date_end=dateend));
end;
else;
set tarifs key=id_tarif/unique;
Total_Cost=Total_Cost+timeCall*price;
run;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: