The last. syntax is not (very easily) available in SQL, so I'd recommend keeping it as two steps:
proc sql;
create table todocomm as
select a.ExternalIdentifier as commnr,
a.identifier as communicationID,
a.communicationtypeid,
a.communicationdescriptionid,
a.inboxforcommunicationID,
a.isincoming as incoming,
a.policyid,
a.policyinstanceid,
a.tscommunicationcreated,
a.datetobecompleted,
a.createdbylogonuserid,
b.externalidentifier as polisnr,
c.tsevent,
c.communicationstatusid
from db2qiso.rpcommunication as a
inner join db2qiso.rppolicy as b
on a.policyid=b.identifier
inner join db2qiso.rpcommunicationevent as c
on a.communicationID = c.communicationid
and int(sum(c.tsevent, 0) / 86400) < &einddat
order by polisnr,
commnr,
c.tsevent;
quit;
data todocomm3;
set todocomm;
by polisnr commnr;
if last.commnr;
if communicationstatusid not in ('00000000003' '00000000004');
drop tsevent communicationstatusid;
run;
... View more