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;
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.