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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.